All pastes #980233 Raw Edit

Traffic light scenario help

public java v1 · immutable
·published 2008-04-10 21:28 UTC
rendered paste body
/** * TrafficLight class to control the state of the lights. A single class * controls the lights in by NS and EW directions. * @author mckaydim * */public class TrafficLight {	private boolean nsLight;	private boolean ewLight;	private int counter;	private int gValue;	private int stepCount;		/**	 * TrafficLight constructor. Sets the initial values for stage 1 of the 	 * traffic light functions.	 */	public TrafficLight(int gVal) {		nsLight = false;			ewLight = true;		gValue = gVal;		counter = gValue;		stepCount = 0;	}		/**	 * At each 'stage' the counter is reset to the appropriate value.	 */	public void tick() {				switch( stepCount ) {			case 0:				stepCount++;				counter = gValue;				nsLight = false;				ewLight = true;			break;			case 1:				stepCount++;				counter = 12;				nsLight = false;				ewLight = false;				break;			case 2:				stepCount++;				counter = gValue;				nsLight = true;				ewLight = false;			break;			case 3:				stepCount = 0; 				counter = 12;				nsLight = false;				ewLight = false;			break;		}		counter--;	}			/**	 * Method for NSLight. If green then returns true. Red returns false.	 * @return boolean	 */	public boolean nsLight() {		return nsLight;	}		/**	 * Method for EWLight. If green then returns true. Red returns false.	 * @return boolean	 */	public boolean ewLight() {		return ewLight;	}			}