-
Notifications
You must be signed in to change notification settings - Fork 975
Expand file tree
/
Copy pathMain.java
More file actions
30 lines (29 loc) · 1.19 KB
/
Main.java
File metadata and controls
30 lines (29 loc) · 1.19 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
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 = 0; i <= 2; i += 1){
System.out.println("— Введите название машины №" + (i + 1) + ":");
String name = scanner.next();
while (true){
System.out.println("— Введите скорость машины №" + (i + 1) + ":");
try{
int speed = Integer.parseInt(scanner.next());
System.out.println();
if(speed > 0 && speed <= 250){
race.controlLead(new Car(name, speed));
break;
}
else{
System.out.println("— Неправильная скорость");
}
}
catch (NumberFormatException e){
System.out.println("— Неправильная скорость");
}
}
}
System.out.println("Самая быстрая машина:" + race.lead);
}
}