Question: Extend the class named Rectangle which you created in the previous assignment. The class needs to contain all of the previous constructors and methods plus
Extend the class named Rectangle which you created in the previous assignment. The class needs to contain all of the previous constructors and methods plus the following items:
A method named setWidth() that sets the width of a rectangle object to a specified width. If the specified width is less than or equal to zero, then it sets the width to one.
A method named setHeight() that sets the height of a rectangle object to a specified height. If the specified height is less than or equal to zero, then it sets the height to one.
Modify your rectangle constructor which includes parameters for width and height to use the setWidth() and setHeight()methods. This will validate the input for both width and height.
Modify the BuildRectangles class to create three separate rectangles with the following specifications:
A rectangle created using the no-arg constructor
A rectangle with a width of -5 and a height of 0
A rectangle with a width of 3.5 and a height of 66.1
Output the information about the three rectangles as you did in the previous assignment:
From your BuildRectangles class, invoke setWidth() and setHeight() to modify the previously created rectangles as follows:
Set the first rectangle to a width of 2.5 and height of 2.7
Set the second rectangle to a width of 5.1 and a height of 6.1
Set the third rectangle to a width of 1.9 and a height of 6.7
Below the output of your initially created rectangle objects, output the modified rectangle information in the same format:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
