Question: Add toString method of the Rectangle class so that it displays the information about the Rectangle object in a user-friendly way (i.e. it informs the

Add toString method of the Rectangle class so that it displays the information about the Rectangle object in a user-friendly way (i.e. it informs the user about the fact that it is a rectangle, and about its dimensions).

Make another class, Square, that is a subclass of Rectangle. The Square constructor should only take one size argument. Think about what can be directly inherited from the Rectangle class and what needs to be overwritten.

Override the toString method from the Rectangle class so that it displays the information about the Square object in a user-friendly way and informs the user about the fact that the object is a square, and about its dimensions.

Make a separate class, SquareTester to test the functionality of the above class. Create a square, print out the information about it using toString method, calculate and display its area and perimeter.

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!