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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started