Question: A. (10 points) Create a class named Rectangle with fields named length , width , and area whose data type is double. Include a constructor

A. (10 points)

Create a class named Rectangle with fields named length, width, and area whose data type is double. Include a constructor that sets the length and width to 1 and calculates the value for the area of the rectangle which is the product of the length and the width. Also, include methods named setLength() , setWidth(), getLength(), getWidth() and getArea(). The setLength() and setWidth() methods not only set the length or width but also calculates the value of the area of the rectangle. Save the class as Rectangle.jave. B. (15 points)

Create a class named TestRectangle whose main() method declares three Rectangle objects. Using the setLength() and setWidth() methods, assign 10 and 20 to the length and width of first Rectangle object respectively, and assign 100 and 200 to the length and width of the second Rectangle object respectively. Assign 30 to the length of the third rectangle; instead, retain the width value assigned at construction. Display all the values of length, width and area for the three Rectangle objects. Save the application as TestRectangle.java.

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!