forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
52 lines (38 loc) · 1.69 KB
/
Main.java
File metadata and controls
52 lines (38 loc) · 1.69 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
46
47
48
49
50
51
52
import java.util.ArrayList;
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("Перед гонкой зарегистрируйте автомобили");
for (int i = 0; i < 3; i++) {
String carName = "";
int carSpeed = -1;
while (carName.isEmpty()) {
System.out.print("Название автомобиля #" + (i + 1) + ": ");
carName = scanner.nextLine();
}
while (true) {
System.out.print("Скорость автомобиля #" + (i + 1) + ": ");
carSpeed = scanner.hasNextInt() ? scanner.nextInt() : -1;
if (carSpeed < 0 || carSpeed > 250) {
System.out.println("Скорость автомобиля должна быть в значении от 0 до 250");
scanner.next();
} else {
break;
}
}
race.Registration(new Car(carName, carSpeed));
scanner.nextLine();
}
System.out.println();
System.out.println("Регистрация автомобилей завершена, старт гонки...");
//Запускаем гонку на 24 часа
race.Start(24);
Car winner = race.getWinner();
//Выводим победителя
System.out.println();
System.out.println("Самая быстрая машина: " + winner.name + ", со скоростью " + winner.speed);
}
}