Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
45 lines (38 loc) · 1.49 KB
/
Copy pathMain.java
File metadata and controls
45 lines (38 loc) · 1.49 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.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Race race = new Race();
for (int i = 1; i <= 3; i++) {
String model;
while (true) {
System.out.println("Выберите марку " + i + " автомобиля");
model = scanner.nextLine();
if (model.trim().isEmpty()) {
System.out.println("Неверная марка автомобиля");
} else {
break;
}
}
int speed;
final int maxSpeed = 250;
final int minSpeed = 0;
while (true) {
try {
System.out.println("Укажите максимальную скорость " + i + " автомобиля");
speed = Integer.parseInt(scanner.nextLine());
if (speed > maxSpeed || minSpeed > speed) {
throw new Exception();
} else {
break;
}
} catch (Exception ex) {
System.out.println("Неверная скорость");
}
}
Car car = new Car(model, speed);
race.race(car.model, car.speed);
}
System.out.println("Самый быстрый автомобиль: " + race.vinner);
}
}