Write in java

Objective: develop a program to simulate the control of traffic lights at an intersection using static methods.
Problem statement: design a system that manages the traffic lights at a four-way intersection, cycling through the different light phases(green,yellow,red).
Requirements:
Handle light phrases- create individual static methods for each phase: redLight(), yellowLight(), greenLight(). Define rules for transitioning between phases, ensuring proper sequencing.
Timing system- implement static methods to manage time intervals, such as setGreenTime(int seconds). Include safety checks to prevent unrealistic timing.
Text-based visualization- use a static method to print the current state of the intersection with ASCII art or a simple text representation.
User interaction- implement a menu system through static methods allowing users to manually control lights or change timings. include validation to ensure user input adheres to traffic regulations.
Sample output:
Welcome to the traffic light controller!
Choose a traffic light phase:
1. Green light
2. Yellow light
3. Red light
4. Exit
1
Intersection Status: Green light
Choose a traffic light phase:
1. Green light
2. Yellow light
3. Red light
4. Exit
2
Intersection Status: Yellow light
Choose a traffic light phase:
1. Green light
2. Yellow light
3. Red light
4. Exit
3
Intersection Status: Red light
Choose a traffic light phase:
1. Green light
2. Yellow light
3. Red light
4. Exit
4
Exiting Traffic Light Controller.

```java

import java.util.Scanner;

public class TrafficLightController {

private static int greenTime = 30; // default green time is set to 30 seconds
private static int yellowTime = 5; // default yellow time is set to 5 seconds
private static int redTime = 40; // default red time is set to 40 seconds

private static void redLight() {
System.out.println("Intersection Status: Red light");
delay(redTime);
}

private static void yellowLight() {
System.out.println("Intersection Status: Yellow light");
delay(yellowTime);
}

private static void greenLight() {
System.out.println("Intersection Status: Green light");
delay(greenTime);
}

private static void delay(int seconds) {
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

private static void printMenu() {
System.out.println("Welcome to the traffic light controller!");
System.out.println("Choose a traffic light phase:");
System.out.println("1. Green light");
System.out.println("2. Yellow light");
System.out.println("3. Red light");
System.out.println("4. Exit");
}

private static void handleUserInput(int choice) {
switch (choice) {
case 1:
greenLight();
break;
case 2:
yellowLight();
break;
case 3:
redLight();
break;
case 4:
System.out.println("Exiting Traffic Light Controller.");
System.exit(0);
break;
}
}

private static void setGreenTime(int seconds) {
if (seconds <= 0) {
System.out.println("Invalid green time value. Default value will be used.");
} else {
greenTime = seconds;
}
}

private static void setYellowTime(int seconds) {
if (seconds <= 0) {
System.out.println("Invalid yellow time value. Default value will be used.");
} else {
yellowTime = seconds;
}
}

private static void setRedTime(int seconds) {
if (seconds <= 0) {
System.out.println("Invalid red time value. Default value will be used.");
} else {
redTime = seconds;
}
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

while (true) {
printMenu();

int choice = scanner.nextInt();

if (choice < 1 || choice > 4) {
System.out.println("Invalid choice. Please try again.");
continue;
}

handleUserInput(choice);
}
}
}
```