-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicle.java
More file actions
39 lines (30 loc) · 960 Bytes
/
Vehicle.java
File metadata and controls
39 lines (30 loc) · 960 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
39
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Vehicle {
public int id;
public int currentX;
public int currentY;
public int currentTime;
public List<Ride> rides;
public Vehicle(int id) {
this.id = id;
this.rides = new ArrayList<Ride>();
}
// add a ride to the list of rides
public void addRide(Ride ride, int startTime) {
this.rides.add(ride);
this.currentX = ride.end.getLeft();
this.currentY = ride.end.getRight();
// the current time for the vehicle from it's start time
// for the ride and the distance travelled
this.currentTime = startTime + ride.distance();
}
public String output() {
return String.format("%d ", rides.size()) +
rides.stream()
.map(r -> r.id)
.map(Object::toString)
.collect(Collectors.joining(" "));
}
}