GofPatterns GofPatterns


Creational Patterns  «Prev  Next»

Concrete Subclasses - Exercise

Objective: Write four concrete subclasses of the Vehicle class.
In this exercise, you will develop concrete subclasses for the Vehicle class, the Bus, Car, Pedestrian, and Bicycle. These are the parameters for the four classes:
  1. The Car class should be 6.0 meters long and have a maximum speed of 120 kilometers per hour.
  2. The Bus class should be 18 meters long with a maximum speed of 92 kilometers per hour.
  3. The Bicycle class should be 1.5 meters long with a maximum speed of 25 kilometers per hour.
  4. The Pedestrian class should have a length of 0 (pedestrians tend to bunch up side by side at intersections rather than queue in line) and a maximum speed of 4 kilometers per hour.
For all of these, all you need to do is define the appropriate class with the necessary constructor that sets the values as specified. A more complex simulation might also add additional behavior to these subclasses, but we will not need that for our simple project.
In the text area below, type or paste your solution and click the Submit button.