
Design a class named rectangle to represent a rectangle. The Class contain: * Two double data fielda named width and heigth 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 specified the color of a rectangle.Hypothetically, assume that all rectangles have the same color. the default color 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 return the area of this rectangle. * A method named getPerimeter() that returns the perimeter.

Java Implement Rectangle class
class rectangle{
double width=1;
double height=1;
String color="white";
rectangle(){
}
rectangle(double w,double h){
this.width=w;
this.height=h;
}
public void setHeight(double height){
this.height=height;
}
public double getHeight(){
return height;
}
public void setWidth(double width){
this.width=width;
}
public double getWidth(){
return width;
}
public void setColor(String color){
this.color=color;
}
public String getColor(){
return color;
}
public double getArea(){
double area=width*height;
return area;
}
public double getPerimeter(){
double p=width+height;
double perimeter=2*p;
return perimeter;
}
public static void main(String[] args){
rectangle rect1=new rectangle();
System.out.println("Width: "+rect1.getWidth());
System.out.println("Height: "+rect1.getHeight());
System.out.println("Color: "+rect1.getColor());
System.out.println("Area: "+rect1.getArea());
System.out.println("Perimeter: "+rect1.getPerimeter());
System.out.println();
rectangle rect2=new rectangle(5,10);
System.out.println("Width: "+rect2.getWidth());
System.out.println("Height: "+rect2.getHeight());
rect2.setColor("Red");
System.out.println("Color: "+rect2.getColor());
System.out.println("Area: "+rect2.getArea());
System.out.println("Perimeter: "+rect2.getPerimeter());
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.