-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathMain.java
More file actions
70 lines (65 loc) · 2.47 KB
/
Copy pathMain.java
File metadata and controls
70 lines (65 loc) · 2.47 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
import java.util.Scanner;
public class Main {
static Car[] carList = new Car[3];
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Добро пожаловать на гонки 24 часа Ле-Мана");
String carmodel;
int speed = 0;
String input;
for (int i = 0; i <= 2; i++) {
while (true) {
System.out.println("Введите марку " + (i + 1) + "-й машины");
carmodel = scanner.nextLine();
if (!(carmodel == null) && !carmodel.isBlank()) {
break;
} else {
System.out.println("Невалидное значение, введите текст");
}
}
while (true) {
System.out.println("Введите скорость " + (i + 1) + "-й машины");
if (scanner.hasNextLine()) {
input = scanner.nextLine();
if (!input.isBlank() && !input.contains(".") && input.matches("\\d+")) {
speed = Integer.parseInt(input);
} else {
System.out.println("Невалидное значение скорости");
input = "mark";
}
if ((speed > 0) && (speed <= 250)) {
break;
} else if (!(input.equals("mark"))) {
System.out.println("Невалидное значение, введите число от 1 до 250");
}
}
}
Car newcar = new Car(carmodel, speed);
carList[i] = newcar;
speed=0;
}
scanner.close();
new Race();
System.out.println("Победитель гонки - " + Race.winner);
}
}
class Car {
String carmodel;
int speed;
Car(String carmodel, int speed) {
this.carmodel = carmodel;
this.speed = speed;
}
}
class Race {
int trip;
static String winner;
public Race() {
for (int i = 0; i < 3; i++) {
if (trip < Main.carList[i].speed * 24) {
trip = Main.carList[i].speed * 24;
winner = Main.carList[i].carmodel;
}
}
}
}