-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaxi.java
More file actions
30 lines (25 loc) · 836 Bytes
/
Taxi.java
File metadata and controls
30 lines (25 loc) · 836 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
import java.util.ArrayList;
public class Taxi {
int id;
char Current_point = 'A';
int total_Earning = 0;
ArrayList<Booking> bookings = new ArrayList<>();
public Taxi(int id) {
this.id = id;
}
public int calculateEarning(char from, char to) {
int distance = Math.abs(to - from) * 15;
int fare = 100 + ((distance > 5 ? (distance - 5) * 10 : 0));
return fare;
}
public boolean isAvailable(int pickupTime) {
if (bookings.isEmpty()) return true;
Booking lastBooking = bookings.get(bookings.size() - 1);
return lastBooking.DropTime <= pickupTime;
}
public void addBooking(Booking booking) {
bookings.add(booking);
total_Earning += booking.amount;
Current_point = booking.to;
}
}