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
56 lines (45 loc) · 2.29 KB
/
Main.java
File metadata and controls
56 lines (45 loc) · 2.29 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("🏁 Добро пожаловать на Гонки суперкаров!");
Race race = new Race();
Scanner scanner = new Scanner(System.in);
for (int i = 1; i <= 3; i++) {
String nameCar;
// Ввод названия автомобиля
while (true) {
System.out.print("Введите название автомобиля " + i + ": ");
nameCar = scanner.nextLine().trim();
if (nameCar.isEmpty()) {
System.out.println("❗ Название не может быть пустым. Попробуйте снова.");
} else {
break;
}
}
int speedCar;
// Ввод скорости автомобиля
while (true) {
System.out.print("Введите скорость автомобиля " + i + " (от 0 до 250, кратна 10): ");
if (scanner.hasNextInt()) {
speedCar = scanner.nextInt();
scanner.nextLine(); // очистка буфера после nextInt()
if (speedCar < 0 || speedCar > 250) {
System.out.println("❗ Скорость должна быть в диапазоне от 0 до 250 км/ч.");
} else if (speedCar % 10 != 0) {
System.out.println("❗ Скорость должна быть кратна 10. Примеры: 60, 100, 240.");
} else {
break;
}
} else {
System.out.println("❗ Введите корректное числовое значение!");
scanner.nextLine(); // очистка некорректного ввода
}
}
// Создание и обработка автомобиля
SportCar car = new SportCar(nameCar, speedCar);
race.returnPath(car);
}
scanner.close();
System.out.println("\n🏆 Самая быстрая машина: " + race.getLeader());
}
}