/* The Intersection class contains four queues (streets) and a light, it defines how cars cross the intersection */ public class Intersection{ //possible values for the traffic light public static final boolean NS_LIGHT = false, EW_LIGHT = true; //the cardinal directions public static final int NORTH = 0, EAST = 1, SOUTH = 2, WEST = 3; //maximum number of time steps private int max; //the current time step private int time; //current state of the traffic lights private boolean light; //a Generator object that adds cars private Generator traffic; //the 4 streets that meet at the intersection private Queue streets[]; //number of cars crossed from each direction private int numcars[]; //total delay experienced by cars from each direction private int cardelay[]; //constructor, specify the number of time steps //and the traffic pattern to use //also initializes the instance variables public Intersection(int duration, Generator pattern){ time = 0; max = duration; light = NS_LIGHT; traffic = pattern; //each street needs a queue and two counters streets = new Queue[4]; numcars = new int[4]; cardelay = new int[4]; for(int i=0;i<4;i++){ streets[i] = new Queue(); numcars[i] = cardelay[i] = 0; } } //helper function that moves 0, 1, or 2 Cars across the intersection private void advance(){ } //helper that flips the lights if needed... //you may want to edit this while testing private void switchLights(){ // just flip every 10 times if(time%10 == 0)light = !light; } //run the simulation public void run(){ for(;time