-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathCars.java
More file actions
35 lines (27 loc) · 885 Bytes
/
Cars.java
File metadata and controls
35 lines (27 loc) · 885 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
package racing;
import java.util.List;
import java.util.stream.Collectors;
public class Cars {
private final List<Car> carList;
public Cars(List<Car> carList) {
this.carList = carList;
}
public List<Car> getCar() {
return carList;
}
public void move(List<Car> carList) {
carList.stream().forEach(car -> car.move((int) Math.round(Math.random())));
}
public int Maxdistance() {
return carList.stream().mapToInt(car -> car.getLocation()).max().getAsInt();
}
public List<String> WinName(int distance) {
return carList.stream().
filter(car -> isSameDistance(distance, car)).
map(name -> name.getName()).
collect(Collectors.toList());
}
private boolean isSameDistance(int distance, Car car) {
return car.getLocation() == distance;
}
}