![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi guys, Im struggling with figuring out a way to make the following code work: public class traffic_light implements Runnable { enum trafficState { Stop, PrepareToGo, Go, PrepareToStop } public String name = ""; public traffic_light(String name) { this.name = name; } public trafficState nowState; public void run () { nowState = trafficState.Go; while (true) { timer(1000); switch (nowState) { case Stop: nowState = trafficState.PrepareToGo; break; case PrepareToGo: nowState = trafficState.Go; break; case Go: nowState = trafficState.PrepareToStop; break; case PrepareToStop: nowState = trafficState.Stop; break; } // End switch this.printOut(nowState); } // End while. } //End Run public void printOut (trafficState state) { System.out.println("The " + name + " traffic lights say " + state); } public static void timer (int delay) { try { Thread.sleep(delay); //timer sleeps for 1 second } catch (InterruptedException exception) { //Does nothing } } // End timer. public static void main (String args[]) { traffic_light trafficLight = new traffic_light("normal"); trafficLight.run(); } // End main. } // End TrafficLight Im just getting 2 errors, both concerning this line: enum trafficState { Stop, PrepareToGo, Go, PrepareToStop } stating that there should be an = before the { and ; expected at the end. Im really not sure how to fix it. Can anyone give any pointers? Thanks in advance, Matt |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |