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
44 lines (37 loc) · 1.58 KB
/
Main.java
File metadata and controls
44 lines (37 loc) · 1.58 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
Car car1 = new Car();
Car car2 = new Car();
Car car3 = new Car();
Car[] cars = {car1, car2, car3};
for (int i = 0; i < cars.length; i++) {
do {
System.out.printf("— Введите название машины №%d:\n", i + 1);
cars[i].name = scanner.nextLine().trim();
if (cars[i].name.isEmpty()) {
System.out.println("— Неправильное название\n");
}
} while (cars[i].name.isEmpty());
System.out.println();
do {
System.out.printf("— Введите скорость машины №%d:\n", i + 1);
try {
cars[i].speed = Integer.parseInt(scanner.nextLine());
if (!(cars[i].speed > 0 && cars[i].speed <= 250)) {
System.out.println("\n— Неправильная скорость\n");
continue;
}
break;
} catch (NumberFormatException e) {
System.out.println("\n— Неправильная скорость\n");
}
} while (true);
System.out.println();
}
Race race = new Race(cars);
Car leader = race.getLeader();
System.out.printf("Самая быстрая машина: %s\n", leader.name);
}
}