Question: Problem: Write a class named Rectangle to represent rectangles. The data fields are width, height, and color. Use double for width and height, and String

Problem: Write a class named Rectangle to represent rectangles. The data fields are width, height, and color. Use double for width and height, and String for color. Suppose that all the rectangles are the same color. You need to provide the accessor methods for the properties and a findArea() method for computing the area of the rectangle.

The outline of the class is given as follows:

The outline of the class is given as follows:

public class Rectangle {

private double width = 1;

private double height = 1;

private String color = "white";

public Rectangle( ) { }

public Rectangle(double widt, double height, String color) { }

public double getWidth( ) { }

public void setWidth( double width) { }

public double getHeight( ) { }

public void setHeight (double height) { }

public String getColor( ) { }

public void setColor ( String color) { }

public double findArea ( ) { }

public String toString ( ) { }

}

Write a client program(test class) to test the class Rectangle. In the client program, create two Rectangle objects. Assign any width and height to the two objects. Assign the first object the color red, and the second, yellow. Display the properties of both objects and find their areas.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!