Question: Program: Better Rectangle The Rectangle class of the standard Java library does not supply a method to compute the area or the perimeter of a

Program: Better Rectangle

The Rectangle class of the standard Java library does not supply a method to compute the area or the perimeter of a rectangle.

Create a subclass BetterRectangle of the Rectangle class that has getPerimeter() and getArea() methods. Neither of these methods will receive values but will return a double value. Do not add any instance variables to your BetterRectangle class. In the parameterized constructor of the BetterRectangle class, call the setLocation and setSize methods of the Rectangle class in order to set the x,y coordinates of the upper left-hand corner of the Rectangle as well as its width and height.

In the main() of the RectangleChecker class, you will:

Ask the user to enter in the x and y coordinates as well as the height and width of a Rectangle.

Create a BetterRectangle object passing the user provided values to the parameterized constructor.

Test your getPerimeter() and getArea() methods on the BetterRectangle object and output the results.

Example output:

Enter x coordinate: Enter y coordinate: Enter width: Enter height: 

with user provided values of x=0, y=0, width=5, height=8 Example output:

The perimeter of the rectangle is: 26.0 The area of the rectangle is: 40.0 

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!