Assignment 12, CS 46A
50 points
due December 8, 2003

Define an A12Simulator class, to be used to perform simple traffic simulations. The simulation is assumed to be of a single traffic light, which traffic may approach either from the north or south, or from the east or west. The timing of the light and the times of arrivals at the light are to be deterimed by the simulator. Your class is to use additional classes TrafficLight and Vehicle to represent the traffic light and vehicles respectively. It should also use an array or ArrayList to represent the collection of vehicles that have passed through the light.

The A12Simulator class is to have a constructor and public methods as in Assignment 9. The TrafficLight class should have a method tick() that informs a TrafficLight object that one time unit has elapsed. Otherwise, you are responsible for the design and interaction of the classes of this assignment.

All counts and averages should include only traffic arriving since the simulator was constructed and departing before the end of the simulation. That is, traffic that is still waiting at the light at the end of the simulation should not be included in the counts and averages. However if the light changes at the very end of the simulation, then this traffic should be allowed to depart and should be included in the statistics. The waiting time should include only the time waiting for the light to turn green, not the time lost in slowing down, in speeding up, or in reaching the light after having stopped. The counts and averages should be the same as those in the sample solution to Assignment 9. In particular, they should include vehicles that have the green light and do not stop.

You may define any additional classes or methods that you find helpful.

For this assignment, you should provide a copy of your code on diskette (no CD or email), hard copies of the code for each of your classes, and a hard copy of the results of your testing with the file A12.java, which is provided on the class web site.