-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathMain.java
More file actions
31 lines (29 loc) · 1.21 KB
/
Main.java
File metadata and controls
31 lines (29 loc) · 1.21 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
import java.io.UnsupportedEncodingException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws UnsupportedEncodingException {
Scanner scanner = new Scanner(System.in);
Race race = new Race();
String name = "default";
double speed = -1;
Car car = new Car(name, speed);
for (int i = 0; i < 3; i++) {
System.out.println("Название автомобиля " + (i + 1) + ":");
name = scanner.next();
do {
System.out.println("Скорость автомобиля " + (i + 1) + ":");
String speedStr = scanner.next();
try {
speed = Double.parseDouble(speedStr);
} catch (Exception e) {
speed = -1;
}
car = new Car(name, speed);
if (!car.isCorrectSpeed()) System.out.println("Неправильная скорость!");
} while (!car.isCorrectSpeed());
race.addCar(car);
}
Car winner = race.getWinner();
System.out.println("Самый быстрый автомобиль -> " + winner.getName());
}
}