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
36 lines (31 loc) · 892 Bytes
/
Race.java
File metadata and controls
36 lines (31 loc) · 892 Bytes
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
/**
* Класс гонки - определяет победителя
*/
public class Race {
private Car[] cars;
private Car leader;
public Race(Car[] cars) {
this.cars = cars;
calculateLeader();
}
/**
* Вычисляем лидера по пройденному расстоянию за 24 часа
*/
private void calculateLeader() {
if (cars == null || cars.length == 0) {
return;
}
leader = cars[0];
double maxDistance = leader.calculateDistance();
for (int i = 1; i < cars.length; i++) {
double currentDistance = cars[i].calculateDistance();
if (currentDistance > maxDistance) {
maxDistance = currentDistance;
leader = cars[i];
}
}
}
public Car getLeader() {
return leader;
}
}