Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
57 lines (45 loc) · 2.2 KB
/
Copy pathMain.java
File metadata and controls
57 lines (45 loc) · 2.2 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
52
53
54
55
56
57
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 часа Ле-Мана ===");
System.out.println("Введите данные для 3 автомобилей\n");
for (int i = 1; i <= 3; i++) {
System.out.println("Автомобиль №" + i + ":");
String carName;
while (true) {
System.out.print("Введите название автомобиля: ");
carName = scanner.nextLine().trim();
if (!carName.isEmpty()) {
break;
} else {
System.out.println("Ошибка: название не может быть пустым. Попробуйте снова.");
}
}
int carSpeed;
while (true) {
System.out.print("Введите скорость автомобиля (0-250 км/ч): ");
try {
String input = scanner.nextLine();
carSpeed = Integer.parseInt(input);
if (carSpeed > 0 && carSpeed <= 250) {
break;
} else {
System.out.println("Ошибка: скорость должна быть в диапазоне от 1 до 250 км/ч. Попробуйте снова.");
}
} catch (NumberFormatException e) {
System.out.println("Ошибка: введите целое число. Попробуйте снова.");
}
}
Car car = new Car(carName, carSpeed);
race.determineLeader(car);
System.out.println("Автомобиль '" + carName + "' успешно добавлен!\n");
}
String winner = race.getLeaderName();
System.out.println("=== Результаты гонки ===");
System.out.println("Победитель: " + winner);
System.out.println("Самая быстрая машина: " + winner);
scanner.close();
}
}