-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicket.java
More file actions
66 lines (47 loc) · 1.6 KB
/
Ticket.java
File metadata and controls
66 lines (47 loc) · 1.6 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.time.LocalTime;
import java.time.Duration;
public class Ticket {
private String ticketID;
private Vehicle vehicle;
private ParkingSpot parkingSpot;
private LocalTime exitTime;
public Ticket(String ticketID, Vehicle vehicle, ParkingSpot parkingSpot) {
this.ticketID = ticketID;
this.vehicle = vehicle;
this.parkingSpot = parkingSpot;
}
public String getTicketID() {
return ticketID;
}
public void setTicketID(String ticketID) {
this.ticketID = ticketID;
}
public Vehicle getVehicle() {
return vehicle;
}
public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}
public ParkingSpot getParkingSpot() {
return parkingSpot;
}
public void setParkingSpot(ParkingSpot parkingSpot) {
this.parkingSpot = parkingSpot;
}
public void setExitTime(LocalTime exitTime){
this.exitTime = exitTime;
}
public LocalTime getExitTime(){
return exitTime;
}
public String calculateDuration() {
if (vehicle.getEntryTime()!= null && exitTime != null) {
Duration duration = Duration.between(vehicle.getEntryTime(), exitTime); // Use Vehicle's entry time and exit time
long hoursTime = duration.toHours();
long minutesTime = duration.toMinutes();
return hoursTime + "hours, " + minutesTime + " minutes." ;
} else {
throw new IllegalStateException("Entry or exit timestamp not set.");
}
}
}