The class contains:
-
Two double data fields named width and height
that specify the width and height of the rectangle. The default values are 1 for both width and
height.
-
A string data field named color that specifies
the color of a rectangle. Hypothetically, assume that all rectangles have the
same color. The default color is white.
-
A no-arg constructor that creates a default
rectangle.
-
A constructor that creates a rectangle with the
specified width and height.
-
The accessor
and mutator methods for all three data fields.
-
A method named getArea() that returns the area
of this rectangle.
-
A method named getPerimeter() that returns the
perimeter.
Draw the UML diagram for the class. Implement the class.
Write a test program that creates two Rectangle objects. Assign width 4 and height 40 to the first
object and width 3.5 and height 35.9 to the second object. Assign color red to all Rectangle
objects. Display the properties of both
objects and find their areas and perimeters.
My question is that i keep gettin this error...RectangleDemo.java:76: reached end of file while parsing
but i'm not sure where to put it, and i dont know if it will work after i had a bracket. could someone please help me
this is what i have:
public class RectangleDemo {
private class Rectangle {
private double height;
private double width;
private String color;
public Rectangle(double wid, double high){
height = high;
width = wid;
}
public Rectangle(){
height = 1;
width = 1;
color = "White";
}
public void setHeight(double high){
height = high;
}
public void setWidth(double wid){
width = wid;
}
public void setColor(String col){
color = col;
}
public double getArea(){
return height*width;
}
public double getPerimeter(){
return 2*(height + width);
}
public void getColor(){
System.out.println("Color is: " + color +"\n");
return;
}
}
public class RectangleDemo {
public static void main(String[] args){
Rectangle box1 = new Rectangle();
Rectangle box2 = new Rectangle(4, 40);
Rectangle box3 = new Rectangle(3.5, 35.9);
String Color = "Red";
box1.setColor(Color);
box2.setColor(Color);
box3.setColor(Color);
box1.getColor();
box2.getColor();
box3.getColor();
System.out.println("The perimeter of the first box is: " + box1.getPerimeter() + "\n");
System.out.println("The perimeter of the second box is: " + box2.getPerimeter() + "\n");
System.out.println("The perimeter of the third box is: " + box3.getPerimeter() + "\n");
System.out.println("The area of the first box is: " + box1.getArea() + "\n");
System.out.println("The area of the second box is: " + box2.getArea() + "\n");
System.out.println("The area of the third box is: " + box3.getArea() + "\n");
}
}