-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooking.java
More file actions
41 lines (37 loc) · 1.13 KB
/
Copy pathBooking.java
File metadata and controls
41 lines (37 loc) · 1.13 KB
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
40
41
class Booking implements Comparable<Booking> {
private final Cars car;
private final RideServices ride;
private final Request request;
private final int waitingTime;
private final int fare;
Booking(Cars car, RideServices ride, Request request) throws IllegalArgumentException {
if (car instanceof Cab && ride instanceof ShareARide) {
throw new IllegalArgumentException(car.toString() + " does not provide the ShareARide service.");
} else if (car instanceof PrivateCar && ride instanceof TakeACab) {
throw new IllegalArgumentException(car.toString() + " does not provide the TakeACab service.");
}
this.car = car;
this.ride = ride;
this.request = request;
waitingTime = car.getAvailTime();
fare = ride.computeFare(request);
}
public int getFare() {
return this.fare;
}
public int getWaitingTime() {
return this.waitingTime;
}
@Override
public int compareTo(Booking b) {
if (fare < b.getFare()) {
return - 1;
} else if (fare > b.getFare()) {
return 1;
} else if (waitingTime < b.getWaitingTime()) {
return -1;
} else {
return 1;
}
}
}