Professional Documents
Culture Documents
Inbound 868855905016311536
Inbound 868855905016311536
BSIT-WMA-3B
Activity 4:
Code:
import java.util.Scanner;
int greenCount = 0;
int redCount = 0;
int orangeCount = 0;
while (true) {
// Create a new TrafficLight object with initial color "red" and duration 30 seconds
switch (input) {
// If input is "red"
case "red":
trafficLight.setColor("red");
trafficLight.setDuration(30);
redCount++;
System.out.println("STOP!!!!\n");
break;
// If input is "green"
case "green":
trafficLight.setColor("green");
trafficLight.setDuration(20);
greenCount++;
System.out.println("GO!!!\n");
break;
// If input is "orange"
case "orange":
trafficLight.setColor("orange");
trafficLight.setDuration(15);
System.out.println("SLOWDOWN!!!\n");
break;
greenCount = 0;
redCount = 0;
orangeCount = 0;
class TrafficLight {
this.color = color;
this.duration = duration;
}
// Getter method for color
return color;
this.color = color;
return duration;
this.duration = duration;
}}
Output: