This repository was archived by the owner on Apr 24, 2025. It is now read-only.
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
29 lines (28 loc) · 1.33 KB
/
Main.java
File metadata and controls
29 lines (28 loc) · 1.33 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
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Car> carsList = new ArrayList<>();
for (int carNumber = 1; carNumber <= 3; carNumber++) {
String carName = "";
int carSpeed = 0;
while (carName.isEmpty()) {
System.out.println("Введите название машины " + carNumber + ": ");
carName = scanner.nextLine();
}
while (carSpeed <= 0 || carSpeed > 250) {
System.out.println("Введите скорость машины");
System.out.println("Скорость должна быть в диапазоне от 1 до 250 км/ч: ");
try {
carSpeed = Integer.parseInt(scanner.nextLine());
} catch (NumberFormatException ignored) {}
}
carsList.add(new Car(carName, carSpeed));
System.out.println("Машина " + carName + " со скоростью " + carSpeed + " км/ч добавлена в гонку");
System.out.println();
}
System.out.println("Самая быстрая машина: " + Race.getWinner(carsList));
System.out.println();
}
}