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
28 lines (22 loc) · 677 Bytes
/
Race.java
File metadata and controls
28 lines (22 loc) · 677 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
package main.java;
import java.util.ArrayList;
public class Race {
private final ArrayList<Car> cars;
private Car winner;
public Race(ArrayList<Car> cars) {
this.cars = cars;
//тут надо кинуть екцепшен если машин меньше 2-х например, но мы их пока не изучали :-)
}
public Car getWinner() {
if (this.winner != null) {
return this.winner;
}
this.winner = cars.get(0);
for (Car car: cars) {
if (car.speed > winner.speed) {
this.winner = car;
}
}
return this.winner;
}
}