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
39 lines (31 loc) · 1.37 KB
/
Main.java
File metadata and controls
39 lines (31 loc) · 1.37 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Race race = new Race();
final int MIN_SPEED = 1;
final int MAX_SPEED = 250;
final int MAX_CARS = 3;
for (int i = 0; i < MAX_CARS; i++) {
System.out.println("Введите название автомобиля " + i + ": ");
String name = scanner.nextLine();
int speed = 0;
while (true) {
System.out.println("Введите скорость автомобиля " + i + " (от " + MIN_SPEED + " до " + MAX_SPEED + "): ");
try {
speed = Integer.parseInt(scanner.nextLine());
if (speed >= MIN_SPEED && speed <= MAX_SPEED) {
break;
} else {
System.out.println("Ошибка: скорость должна быть от 1 до 250.");
}
} catch (NumberFormatException e) {
System.out.println("Ошибка: введите целое число.");
}
}
Car car = new Car(name, speed);
race.checkWinner(car);
}
System.out.println("Самая быстрая машина: " + race.getWinnerName());
}
}