Design a basic traffic light controller. Create methods to handle different light states (red, yellow, green) and cycle through them. The main method should simulate the traffic light cycle. Input is the current state (0 for red, 1 for yellow, 2 for green), and output is the next state and action.
Functional decomposition
Stop, yield, go: Traffic conductor's waltz
Report a typo
Sample Input 1:
0Sample Output 1:
1
Change to YellowSample Input 2:
1Sample Output 2:
2
Change to GreenWrite a program in Java 17
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int currentState = scanner.nextInt();
scanner.close();
String nextState = getNextState(currentState);
String action = getAction(currentState);
System.out.println(nextState);
System.out.println(action);
}
public static String getNextState(int currentState) {
}
public static String getAction(int currentState) {
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.