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
45 lines (40 loc) · 1.78 KB
/
Main.java
File metadata and controls
45 lines (40 loc) · 1.78 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
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<Car> cars = new ArrayList<>();
Scanner sc = new Scanner(System.in);
Race race = new Race();
int carSpeed;
int minCarSpeed = 0;
int maxCarSpeed = 250;
int countCar = 3;
while (cars.size() < countCar) {
System.out.println("Введите название машины под номером " + (cars.size() + 1) + ":");
String carName = sc.next();
System.out.println("Введите скорость машины под номером " + (cars.size() + 1) + ":");
while (true) {
if (sc.hasNextInt()) {
carSpeed = sc.nextInt();
if (carSpeed >= minCarSpeed && carSpeed <= maxCarSpeed) {
Car car = new Car(carName, carSpeed);
cars.add(car);
race.selectWinner(car);
} else {
System.out.println("Введена некорректная скорость. Введите заново: ");
continue;
}
break;
} else {
System.out.println("Введена некорректная скорость. Введите заново: ");
sc.next();
}
}
}
System.out.println("Участники гонки:");
for (Car car : cars) {
System.out.println("Первая машина: " + car.name + "\nСкорость:" + car.speed);
}
System.out.println("Самая быстрая машина(-ы): " + race.raceWinner);
}
}