forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRace.java
More file actions
41 lines (34 loc) · 1.32 KB
/
Race.java
File metadata and controls
41 lines (34 loc) · 1.32 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
public class Race {
private String leaderName;
private int leaderDistance;
private static final int RACE_TIME = 24;
public Race() {
this.leaderName = "";
this.leaderDistance = 0;
}
// Метод для определения нового лидера
public void checkLeader(Car car) {
int carDistance = RACE_TIME * car.getSpeed();
// Сравниваем дистанцию нового автомобиля с дистанцией текущего лидера
if (carDistance > leaderDistance) {
leaderName = car.getName();
leaderDistance = carDistance;
}
}
public String getLeaderName() {
return leaderName;
}
public int getLeaderDistance() {
return leaderDistance;
}
// Метод для вывода итогов гонки
public void printRaceResults() {
if (leaderName.isEmpty()) {
System.out.println("Гонка не состоялась или не было участников");
} else {
System.out.println("\n=== ГОНКА ЗАВЕРШЕНА ===");
System.out.println("Победитель: " + leaderName);
System.out.println("Пройденная дистанция: " + leaderDistance + " км");
}
}
}