Week 5 : Abstract Class & Interface solution


Original Work ?


5/5 - (3 votes)

Question 1 – Revisiting the Triangle

Refer to the Triangle class from Lab3 Question 1.
Provide an alternative implementation of the Triangle class based on the following specification:

Have a ShapeManager class that holds the main() loop.

(a) Which of the methods of the Triangle class did you have to change? Why?

(b) Which is a better design – Lab#5 Question 1 or Lab#3 Question 1? Why?

Question 2 – Abstract Class or Interface?

Create a Virtual World (game!) where the following entities exist:

Person, Student, CSEStudent (reuse from Lab#4 )
Auto, Car, Bicycle.
All vehicles have the attribute numWheels and will honk().

All entities in the Virtual World will need to move forward and backward. (Hint: void forward(double distance), void backward(double distance))

(a) Design the Vehicle hierarchy, explaining the use of abstract class / concrete class / interface.

(b) Draw the class diagram for the Virtual World, consisting of the Person hierarchy and Vehicle hierarchy. Explain how movement is incorporated in your design.

(c) Implement your design from part (b) with a VirtualWorldManager.

Expected Output
PERSON – walking 1km forward
AUTO – driving 0.2km backward on 3 wheels
Bicycle – pedalling 5km forward on 2 wheels
Student – walking 0.5km forward
CSEStudent – walking 2km backward
Car – driving 10km forward on 4 wheels