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
45 lines (34 loc) · 1.5 KB
/
Main.java
File metadata and controls
45 lines (34 loc) · 1.5 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
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("Добавьте машины для гонки. Для выхода введите 'стоп'.");
while (true) {
System.out.print("Введите название машины: ");
String name = scanner.nextLine();
if (name.equals("стоп")){
break;
}
int speed = -1;
while (speed < 0 || speed > 350) {
System.out.print("Введите скорость машины (0-350 км/ч): ");
try {
speed = scanner.nextInt();
if (speed < 0 || speed > 350) {
System.out.println("Ошибка: скорость должна быть от 0 до 350!");
}
} catch (Exception e) {
System.out.println("Ошибка: введите число!");
scanner.nextLine(); // Очистка буфера
}
}
scanner.nextLine();
Car car = new Car(speed, name);
String result = race.getLeaderName(car);
System.out.println("Текущий лидер: " + result);
}
System.out.println("Финальный результат: " + race.getLeaderName());
scanner.close();
}
}