/** TrafficLightDemo.java --- main program in Java
 * @author Uwe Assmann
 * @version 1.0
 * @date 2015-04-08
 */

// for import of System.out.println()
import java.util.*;

/**
   Simple main program of CommandLineDemo, is called by the run-time system (operating system). 
   Main operation "main" is a class operation, i.e., exists only once.
   Just print all arguments given in args[]
 */
public class TrafficLightDemo {
    public static void main(String args[]) { 
	if (args.length == 0) {
	    return;
	}
	int i = Integer.parseInt(args[0]);
	TrafficLight trafficLight;
	int j = 0;
	while (j < i) {
	    System.out.println("Traffic light "+j);
	    trafficLight = new TrafficLight(j);
	    j++;
	}
	
	System.out.println(".");
    }
}


class TrafficLight {
    private String state; 
    private int mynumber; 

    // Constructor
    public TrafficLight (int number) {  mynumber = number; state = "blinking"; }

    public void switchIt () {
	if (state.equals("green")) state = "yellow";
	if (state.equals("yellow")) state = "red";
	if (state.equals("red")) state = "redyellow";
	if (state.equals("redyellow")) state = "green";
    }
    public void switchOn () {
	state = "red";
    }
    public void switchOff () {
	state = "blinking";
    }
}
