Define a Simulator class, to be used to support 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 deterimed outside of the simulator.Your class is to have the following methods:
void processArrival method that processes the arrival of a vehicle at a traffic light. The method is to take a vehicle's arrival time, the time at which its traffic light will turn green, and a boolean flag that has value true if and only if the vehicle is headed north or south, and is to update the state of the simulator so that the methods below will return appropriate values.
void reset method that resets the state of the simulator to its initial value.
int getNSVehicleCount that returns a count of all of the vehicles that have arrived at the traffic light heading north or south
int getEWVehicleCount that returns a count of all of the vehicles that have arrived at the traffic light heading east or west
int getVehicleCount that returns a count of all of the vehicles that have arrived at the traffic light
double computeAverageNSWaitingTime that returns the average waiting time in seconds of all of the vehicles that have arrived at the traffic light heading north or south
double computeAverageEWWaitingTime that returns the average waiting time in seconds of all of the vehicles that have arrived at the traffic light heading east or west
double computeAverageWaitingTime that returns the average waiting time in seconds of all of the vehicles that have arrived at the traffic light
All counts and computations should include only traffic arriving since the simulator was constructed or last reset. 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.
For this assignment, you should provide a copy of your code on diskette (no CD or email), and hard copies of your code and the results of your testing with the file A8Simulation.java, which is provided on the class web site.
It will not be immediately clear whether the answers that you print are correct. You can do some checking by
System.out, appropriate information about each arrival. When doing this, you might consider reducing the number of cycles. Make sure to reset this number, and delete any code used for this sort of printing, before you turn in your solution.
Note that the A8Simulation.java file contains some simulation detail and is thus not optimally designed for simulations -- especially repeated simulations. You will have an opportunity to address this issue in Assignment 9.