-
Notifications
You must be signed in to change notification settings - Fork 1
/
TrafficSignal.java
37 lines (29 loc) · 937 Bytes
/
TrafficSignal.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class TrafficSignal {
public static void main(String[] args) {
SignalColor currentColor = SignalColor.RED;
for (int i = 1; i <= 10; i++) {
System.out.println("Iteration " + i + ": " + currentColor);
switch (currentColor) {
case RED:
currentColor = SignalColor.GREEN;
break;
case GREEN:
currentColor = SignalColor.YELLOW;
break;
case YELLOW:
currentColor = SignalColor.RED;
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private enum SignalColor {
RED,
GREEN,
YELLOW
}
}