forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
52 lines (40 loc) · 1.52 KB
/
Main.java
File metadata and controls
52 lines (40 loc) · 1.52 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
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Race race = new Race();
for (int i = 1; i <= 3; i++) {
System.out.println("Введите название машины №" + i);
String name = scanner.next();
System.out.println("Введите скорость машины №" + i);
while (true) {
if (scanner.hasNextInt()) {
int speed = scanner.nextInt();
if (speed > 0 & speed <= 250) {
race.calculate(name, speed);
break;
}
else {
System.out.println("Введено неверное значение. Попробуйте еще раз.");
}
} else {
scanner.nextLine();
System.out.println("Введите целое число");
}
}
}
System.out.println("Самая быстрая машина: " + race.leader);
}
}
class Race {
String leader = "";
int leaderDistace = 0;
void calculate(String name, int speed) {
int distance;
distance = 24 * speed;
if (distance > leaderDistace) {
leader = name;
leaderDistace = distance;
}
}
}