GofPatterns GofPatterns

Design Patterns  «Prev  Next»
Lesson 8Course project, part 2
ObjectiveWrite classes for traffic signals

Course Project - Traffic Signals

Write the classes for the traffic signals in the course project. As the first part of the course project, let us create the traffic lights and Walk/Don't Walk signs.

Here are some of the specifications for the project:
  1. Traffic lights have an intermediate yellow state, and always pass through their three possible states in the cyclic order red/green/yellow/red.
  2. Walk/Don't Walk signs have an intermediate flashing don't walk state, and always pass through their three possible states in the cyclic order walk/flashing don't walk/don't walk/walk.
  3. There should be a minimum time associated with each light state (for instance, you don't want pedestrians to have to race across the street in under 5 seconds). However, the traffic light probably should not have a maximum time on green.
    Other states may need maximum times to allow the traffic light to revert to green (Remember, pedestrians have to push a button to get a walk sign. If no one pushes a button, the pedestrian signal remains locked in "Don't Walk").
  4. By default, the traffic light is green until a pedestrian pushes a button on the light indicating they wish to cross the street.
  5. Most importantly, the lights must be connected. It is important to insure that whenever the traffic light is green, the crosswalk sign reads,
    Don't Walk

Abstract Traffic Signal - Exercise

In this exercise, you will be writing the classes for the traffic lights.
Abstract Traffic Signal - Exercise