Using the inheritance and polymorphism concepts you have studied in this course, implement the Shape hierarchy shown in the above figure. Each shape has a color, date of creation and border style. Each TwoDimensionalShape should contain method getArea to calculate the area of the two-dimensional shape. Each ThreeDimensionalShape should have methods getArea and getVolume to calculate the surface area and volume, respectively, of the three-dimensional shape. Create a program that uses an array of Shape references to objects of each concrete class in the hierarchy. The program should print a text description of the object to which each array element refers. Also, in the loop that processes all the shapes in the array, determine whether each shape is a TwoDimensionalShape or a ThreeDimensionalShape. If it’s a TwoDimensionalShape, display its area. If it’s a ThreeDimensionalShape, display its area and volume.
Implement one method that can receive as arguments references to any two Shape objects (of the same type or of different types) and return true if the two shapes have the same area/surface area.
The world of shapes is much richer than the shapes included in the inheritance hierarchy shown above. Suggest and implement one more two-dimensional shape and one more three-dimensional shape. Do you have to change anything in the method you developed in part 2 so that it can handle the new shapes you have added?
Many programs written with inheritance could be written with composition instead, and vice versa. Give an example of your choice to support this fact.