-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWork.java
More file actions
42 lines (35 loc) · 1.18 KB
/
Work.java
File metadata and controls
42 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ru.lessons.Pavel.trafficLight;
import java.util.ArrayList;
import java.util.Scanner;
class Work {
private Color red;
private Color yellow;
private Color green;
void init() {
red = new Red("Красный");
yellow = new Yellow("Желтый");
green = new Green("Зеленый");
ArrayList<Color> colors = new ArrayList<>();
colors.add(red);
colors.add(yellow);
colors.add(green);
Scanner scanner = new Scanner(System.in);
for (Color color : colors) {
System.out.println("Введите количество секунд для цвета: " + color.getName());
while (color.getSeconds() == 0) {
if (scanner.hasNextInt()) {
int seconds = scanner.nextInt();
color.setSeconds(seconds);
} else {
System.out.println("Введите числовое значение: ");
scanner.next();
}
}
}
}
void start() {
red.toBurn();
yellow.toBurn();
green.toBurn();
}
}