Stop, yield, go: Traffic conductor's waltz

Report a typo

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.

Sample Input 1:

0

Sample Output 1:

1
Change to Yellow

Sample Input 2:

1

Sample Output 2:

2
Change to Green
Write 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) {

}
}
___

Create a free account to access the full topic