Question: Design a class named Rectangle ( Rectangle.java ) to represent a rectangle. The class contains: ? Two private double data fields named width and height
Design a class named Rectangle (
Rectangle.java
) to represent a rectangle. The class
contains:
?
Two private double data fields named
width
and
height
that specify the width and
height of the rectangle. The default value for
width
is 2.0, and 1.0 for
height
.
?
A public no-arg constructor that creates a default rectangle.
?
A public constructor that creates a rectangle with the specified
width
and
height
.
?
The public accessor and mutator methods for
width
and
height
.
?
A public method named
getArea()
that returns the area of this rectangle.
?
A public method named
getPerimeter()
that returns the perimeter of this rectangle.
Draw the UML diagram (
RectangleUML.docx
) for the class and then implement the
class. Write a test program (
RectangleTest.java
) that creates a Rectangle object with
width 40.0 and height 4.0 and display its width, height, area, and perimeter. Then change
its width to 35.9 and height to 3.5 and display its width, height, area, and perimeter again.
The output should look exactly like the following:
Before the change:
The rectangle's width is 40.00 and its height is 4.00.
Its area is 160.00 and its perimeter is 88.00.
After the change:
The rectangle's width is 35.90 and its height is 3.50.
Its area is 125.65 and its perimeter is 78.80.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
