Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
38 lines (35 loc) · 1.67 KB
/
Copy pathMain.java
File metadata and controls
38 lines (35 loc) · 1.67 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Race race = new Race();
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
System.out.println("Введите название машины: ");
String name = scanner.next();
System.out.println("Название машины №" + (i + 1) + ": " + name);
System.out.println("Введите скорость машины от 0 до 250: ");
while (true) {
String input = scanner.nextLine().trim();
if(input.isEmpty()){
continue;
}
try {
int speed = Integer.parseInt(input);
if (speed > 0 && speed <= 250) {
System.out.println("Скорость машины № " + (i + 1) + ": " + speed);
Auto autosValue = new Auto(name, speed);
race.calculateWinner(autosValue);
break;
} else if (speed <= 0 || speed > 250){
System.out.println("Недопустимое значение скорости. Скорость машины должна быть от 0 до 250");
}
} catch (NumberFormatException error){
System.out.println("Некорректное значение. Попробуйте снова");
}
}
race.winner = race.getWinner();
}
System.out.println("Победитель: " + race.winner);
scanner.close();
}
}