forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
51 lines (41 loc) · 1.85 KB
/
Main.java
File metadata and controls
51 lines (41 loc) · 1.85 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
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Race race = new Race();
System.out.println("24 часа Ле-Мана");
for (int i = 1; i <= 3; i++) {
System.out.println("\nАвтомобиль №" + i);
System.out.println("Введите название машины: ");
String carName = scanner.nextLine();
while (carName.trim().isEmpty()) {
System.out.println("Ошибка: название не может быть пустым!");
System.out.println("Введите название машины:");
carName = scanner.nextLine();
}
int carSpeed = 0;
boolean speedIsCorrect = false;
while (!speedIsCorrect) {
System.out.println("Введите скорость машины: ");
if (scanner.hasNextInt()) {
carSpeed = scanner.nextInt();
scanner.nextLine();
if (carSpeed > 0 && carSpeed <= 250) {
speedIsCorrect = true;
} else if (carSpeed <= 0) {
System.out.println("Ошибка: скорость должна быть больше 0!");
} else {
System.out.println("Неправильная скорость!");
}
} else {
System.out.println("Ошибка: введите целое число!");
scanner.nextLine();
}
}
Car car = new Car(carName, carSpeed);
race.updateLeader(car);
}
scanner.close();
System.out.println("\n" + race.getWinner());
}
}