Q:

COS 102 Programming 2 project OOP JAVA

0

Part 1:

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.

Part 2:

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.

Part 3:

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?

Part 4:

Many programs written with inheritance could be written with composition instead, and vice versa. Give an example of your choice to support this fact.

All Answers

total answers (0)

Similar questions


need a help?


find thousands of online teachers now