Behavioral Patterns  «Prev  Next»

Signal Mediator Class - Exercise

Course Project, Part 6

Objective: Write a SignalMediator class for the intersection that manages the four lights.
The SignalMediator is responsible for queuing requests and making sure that each light is green for a minimum amount of time. Furthermore, the mediator should provide access to the individual lights. The basic algorithm you want to implement has seven states that are cycled through in the following order. You can play with the minimum and maximum times if you like, but you must keep this order.

State East West North South walk request Min Max
1 Go Go Stop Stop false 120 Inf
2 Go Go Stop Stop true 0 60
3 Caution Caution Stop Stop true 12 12
4 Stop Stop Stop Stop true 5 5
5 Stop Stop Go Go false 60 60
6 Stop Stop Caution Caution false 20 20
7 Stop Stop Stop Stop false 5 5
1 Go Go Stop Stop false 120 inf

The Inf in state one means that the east-west lights stay green until a pedestrian on the north-south direction explicitly requests a walk signal. This is one of the most important classes in the system. It also offers many options for how it is written, so I am going to leave the exact details open. In the text area below, type or paste your answer and click the Submit button.