Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
39 lines (38 loc) · 1.7 KB
/
Copy pathMain.java
File metadata and controls
39 lines (38 loc) · 1.7 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) {
Scanner in = new Scanner(System.in);
Automobile[] autos = new Automobile[3]; //Автомобили - участники гонки
// Переменные для информации об автомобиле
double speed;
String name = "";
// Ввод
for (short i = 0; i < 3; i++) {
name = "";
while (name.isEmpty()) {
System.out.println("Введите название автомобиля " + (i + 1));
name = in.nextLine(); //допускаем имя автомобиля с пробелами
}
speed = -1.0;
while (!((speed >= 0) && (speed <= 250))) {
System.out.println("Введите скорость автомобиля " + (i + 1));
String speedStr = in.nextLine();
try {
speed = Double.parseDouble(speedStr);
} catch (Exception e) {
System.out.println("Неправильная скорость!");
continue;
}
if (!((speed >= 0) && (speed <= 250))) {
System.out.println("Неправильная скорость!");
}
}
Automobile auto = new Automobile(name, speed);
autos[i] = auto;
}
System.out.println("Ввод успешно завершён!");
Gonka gonka = new Gonka(autos);
Automobile leader = gonka.startAndGetLeader(24);
System.out.println("Самая быстрая машина: " + leader.name);
}
}