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
39 lines (31 loc) · 1.44 KB
/
Main.java
File metadata and controls
39 lines (31 loc) · 1.44 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to the race 24 Hours of Le Mans!\n");
Scanner input = new Scanner(System.in);
Race newRace = new Race();
for (int i = 0; i < 3; i++) {
System.out.println("Enter title of car №" + (i + 1) + ":");
String carTitle = input.next();
int carSpeed = -1;
do {
System.out.println("Enter speed of car №" + (i + 1) + ":");
if (input.hasNextInt()) {
carSpeed = input.nextInt();
if (!(carSpeed > 0 && carSpeed <= 250)) {
carSpeed = -1;
System.out.println("Error! The speed might be from 0 to 250");
}
} else {
System.out.println("Error! Please enter only integer");
input.next(); // очищаем input от неправильного ввода
}
} while (carSpeed < 0);
Car newCar = new Car(carTitle, carSpeed);
System.out.println("New race participant: " + newCar.title + " with speed " + newCar.speed);
newRace.cars.add(newCar);
newRace.scoring();
System.out.println("The winner of this race is " + newRace.getWinner().title + " with score " + newRace.getWinnerScore());
}
}
}