Due by the end of Tuesday, 23 February 2021
Note that one of the messages about equals will be obviously wrong!
Rectangles should be equal if they have the same height and width.
Run the program again to make sure it's giving the proper answers.
NOTE: If a Square is a Rectangle, then it has a width and a height, because Rectangles have a width and a height.
Create a constructor for the class. It should be given only one value -- the length of its sides.
Remember, it is a Rectangle, so it has a width and height; they just need to be the same.
Override the toString method so that it makes an appropriate String (such as "5x5 Square").
Do not override any methods you don't need to!
Test your code by un-commenting the code for Activity 2 in TestRectangles. You'll get a bit more output, starting with:
Note that the Squares get broken in the last bit of the program.
NOTE: your program might say "5x5 Square" or "10x10 Square" instead of "5x10 Square". That's fine. The important thing is that the measurements reported match the ones shown.
The next activity will fix that problem.
Hint: a Rectangle can set its height and width separately, so a Square just has to avail itself of those inherited methods. (But without going into an infinite recursion!) If you ask a square to change its height, then it needs to change both its height and its width. Where are its height and width stored? Which methods can manipulate them directly?
Run the program again to make sure that the Squares at the end of the program actually are squares.
Submit this/these files:
You will be graded on the following: