import java.util.Random; // Enum to represent the traffic light states enum TrafficLightState { RED, YELLOW, GREEN } // Class to represent a Traffic Light class TrafficLight { private TrafficLightState state; public TrafficLight() { state = TrafficLightState.RED; } public TrafficLightState getState() { return state; } public void changeState(TrafficLightState newState) { state = newState; } } // Class to represent a Vehicle class Vehicle { private String id; public Vehicle(String id) { this.id = id; } public String getId() { return id; } } // Main Traffic Management System class public class TrafficManagementSystem { public static void main(String[] args) { TrafficLight trafficLight = new TrafficLight(); Random random = new Random(); // Simulate the traffic signal and vehicle behavior for (int i = 0; i < 10; i++) { // Change traffic light state randomly int randomStateIndex = random.nextInt(TrafficLightState.values().length); TrafficLightState newState = TrafficLightState.values()[randomStateIndex]; trafficLight.changeState(newState); System.out.println("Traffic Light is now " + newState); // Simulate vehicles approaching the signal int numVehicles = random.nextInt(10); for (int j = 0; j < numVehicles; j++) { Vehicle vehicle = new Vehicle("Vehicle " + j); System.out.println(vehicle.getId() + " is approaching the signal."); // Check if the vehicle should stop or proceed if (newState == TrafficLightState.RED) { System.out.println(vehicle.getId() + " must stop."); } else { System.out.println(vehicle.getId() + " can proceed."); } } System.out.println(); } } }