Question
You will be creating a driver class and 5 class files for this assignment. The classes are Shape2D (the parent class), Circle, Triangle, and Rectangle
You will be creating a driver class and 5 class files for this assignment. The classes are Shape2D (the parent class), Circle, Triangle, and Rectangle (all children of Shape2D) and Square (child of Rectangle).
You also need to make the Shape2D class abstract that means dont use a constructor method in Shape2D
Within the driver class, please complete the following tasks:
Instantiate an array of four (4) Shape2D objects.
Instantiate a Circle object as the first object in the array. Create the circle with 1 side and a radius of 4; print it with a heading like Original circle:
Update the radius of the Circle to 7; reprint the circle using a heading like Updated circle:
Instantiate an equilateral Triangle object as the second object in the array with 3 sides and a side length of 3.
Instantiate a Rectangle object as the third object in the array with 4 sides, a length of 2 and a width of 5.
Instantiate a Square object as the fourth object in the array with 4 sides and side lengths of 6.
After printing a heading (ex. -----Listing of all shapes-----), use a for loop to print out the contents of the array, one object per line.
You also need to run the numCorners method for each object to print out how many corners each of the objects has.
Within each object class you must include the following methods unless inherited from the parent class or it provides updated functionality relevant to the class:
A constructor method that accepts parameters including the number of sides the object has and all values required to calculate area and perimeter/circumference.
Getter and setter methods for all instance data except the number of sides.
Methods to calculate the area and perimeter/circumference.
A numCorners method that returns a statement (String) that lists the name of the object and how many corners it has.
ex. A circle has 0 corners.
NOTE: Within the Shape2D class, this method is abstract (serves as a template for the methods that are contained within the child classes).
A toString method which provides a description (one or two lines) about the object that includes the number of sides it has, its area, and its perimeter/circumference.
All calculated values must be printed with up to 2 decimal places.
Sample format: A circle is an object with 1 side(s). It has a radius of 4, an area of 50.27 and a circumference of 25.13
Include clear comments throughout the program that explain the well named variables and what functionality the various lines/small sections of code are completing as related to the execution of the program.
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