Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Done in Java. Any help is appreciated! We have review a java class Rectangle that defines a rectangle by its top left corner and height/width
Done in Java. Any help is appreciated!
We have review a java class Rectangle that defines a rectangle by its top left corner and height/width values. Implement a subclass Square by extending the Rectangle class such that a square is defined by its center position and the side length. In the constructor, accept the x- and y-positions of the center and the side_length of the square and use constructor chaining when creating your square. Also use methods from Rectangle class whenever available and keep your own code in square class to the minimum. You may want to look up these methods in the documentation for the Rectangle class. Do not write any new method in Square class with functionality that is provided by Rectangle class. Also supply two other methods getArea() and getPerimeter() which compute and return the area and perimeter of the square respectively. Write a sample program that creates an ArrayList of 5 squares with different center points and different side lengths. Prints all squares (i.e., center points and side lengths, their areas, and perimeters) using the toString method {be sure to override the toString method to print the ArrayList or each Square object from the list in a proper format}
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