-
Notifications
You must be signed in to change notification settings - Fork 963
Expand file tree
/
Copy pathMain.java
More file actions
37 lines (31 loc) · 1.23 KB
/
Main.java
File metadata and controls
37 lines (31 loc) · 1.23 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Race race = new Race();
int speed = 0;
for (int i = 1; i <= 3; i = i + 1) {
System.out.println("Введите название машины №" + i);
String brand = scanner.next();
boolean validInput = false;
while (!validInput) {
System.out.println("Введите скорость машины №" + i);
if (scanner.hasNextInt()) {
speed = scanner.nextInt();
if (speed >= 0 && speed <= 250) {
validInput = true;
} else {
System.out.println("Неправильная скорость");
}
} else {
System.out.println("Неправильная скорость");
scanner.next();
}
}
Auto auto = new Auto(brand, speed);
race.updateWinner(auto.getBrand(), auto.getSpeed());
}
scanner.close();
System.out.println(race.getCurrentWinner());
}
}