-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathRace.java
More file actions
38 lines (33 loc) · 838 Bytes
/
Race.java
File metadata and controls
38 lines (33 loc) · 838 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
37
38
package model;
import java.util.List;
import java.util.ArrayList;
import view.Output;
public class Race {
private final List<Car> cars;
private final int move;
public Race(List<Car> cars, int move) {
this.cars = cars;
this.move = move;
}
public void start(){
for(int i = 0; i < move; i++) {
for (Car car : cars) {
car.move();
}
Output.printResult(cars);
}
}
public List<String> getWinner() {
int max = 0;
for (Car car : cars) {
max = Math.max(max, car.getPos());
}
List<String> winners = new ArrayList<>();
for (Car car : cars) {
if (car.getPos() == max) {
winners.add(car.getName());
}
}
return winners;
}
}