forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
33 lines (30 loc) · 1.26 KB
/
Main.java
File metadata and controls
33 lines (30 loc) · 1.26 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("24 часа Ле-Мана");
Scanner scanner = new Scanner(System.in);
int numberOfCars = 3;
Race rs = new Race();
for (int i = 0; i<numberOfCars; i++){
System.out.println("— Введите название машины № " + (i+1));
String brand = scanner.next();
for(;true;) {
System.out.println("— Введите скорость машины № " + (i + 1));
if (scanner.hasNextInt()){
int speed = scanner.nextInt();
if (speed>0 && speed<=250){
rs.addCarToRace(new Car(brand,speed));
break;
} else {
System.out.println("— Неправильная скорость ");
}
} else {
System.out.println("— Неправильная скорость, не число");
scanner.next();
}
}
}
System.out.println("Самая быстрая машина: " + rs.getWinner());
scanner.close();
}
}