Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
88 lines (61 loc) · 2.15 KB
/
Copy pathMain.java
File metadata and controls
88 lines (61 loc) · 2.15 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Gonka gonka = new Gonka();
String[] names = new String[3];
int[] speeds = new int[3];
for (int i = 0; i < 3; i++) {
while (true) {
System.out.println("Введите название машины №" + (i + 1) + ":");
names[i] = scanner.nextLine();
if (names[i].trim().isEmpty()) {
System.out.println("Название не может быть пустым.");
continue;
}
break;
}
while (true) {
System.out.println("Введите скорость машины №" + (i + 1) + ":");
if (scanner.hasNextInt()) {
speeds[i] = scanner.nextInt();
scanner.nextLine();
if (speeds[i] < 0 || speeds[i] > 250) {
System.out.println("Правильная скорость от 0 до 250.");
continue;
}
break;
} else {
System.out.println("Ошибка. Введите целое число");
scanner.nextLine();
}
}
}
for (int j = 0; j < 3; j++) {
gonka.newLider(names[j], speeds[j]);
}
gonka.finalLider();
}
}
class Gonka {
String lider = "";
int liderDist = 0;
public void newLider(String name, int speed) {
int dist = 24 * speed;
if (dist > liderDist) {
lider = name;
liderDist = dist;
}
}
public void finalLider() {
System.out.println("Самая быстрая машина:" + lider);
}
}
class Auto {
String name;
int speed;
public Auto(String name, int speed) {
this.name = name;
this.speed = speed;
}
}