Blasterboy460
[H]ard|Gawd
- Joined
- Aug 2, 2002
- Messages
- 1,610
so the problem is
Question 6.1 (the rectangle class) Write a class named rectangle to represent rectangles. The UML diagram for the class is shown in figure 6.25. Suppose that all the rectangles are the same color. Use a static variable for color.
write a client program to test the rectangle. in the client program, create two rectangle objects with a width of 4 and height of 40 to each object. asign color as yellow. display the properties of both objects and find their areas
ive gotten this far but i have errors and i know im doing this wrong. can anyone give me some tips and not nessacarily code for me.
Question 6.1 (the rectangle class) Write a class named rectangle to represent rectangles. The UML diagram for the class is shown in figure 6.25. Suppose that all the rectangles are the same color. Use a static variable for color.
write a client program to test the rectangle. in the client program, create two rectangle objects with a width of 4 and height of 40 to each object. asign color as yellow. display the properties of both objects and find their areas
ive gotten this far but i have errors and i know im doing this wrong. can anyone give me some tips and not nessacarily code for me.
Code:
//Brett Jackson
//Program 2
//Rectangle project
//CMPS 257
public class Program2 {
public static void main(String[] args) {
//declaring objects
Rectangle rectangle1 = new Rectangle(1);
Rectangle rectangle2 = new Rectangle(2);
//setting the width heigh and color
rectangle1.width = 4;
rectangle2.width = 4;
rectangle1.height = 40;
rectangle2.height = 40;
rectangle1.color = "yellow";
rectangle2.color = "yellow";
//rectangle1 output
System.out.println("rectangle 1 has a width of " + rectangle1.width + " and a height of " + rectangle1.height);
System.out.println("The color of rectangle 1 is " + rectangle1.color);
System.out.println("The area of rectangle 1 is " + rectangle1.area);
//rectangle2 output
System.out.println("rectangle 1 has a width of " + rectangle2.width + " and a height of " + rectangle2.height);
System.out.println("The color of rectangle 1 is " + rectangle2.color);
System.out.println("The area of rectangle 1 is " + rectangle2.area);
}
}
//new class called rectangle
class Rectangle {
double area = height * width;
}