-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooking.java
127 lines (99 loc) · 3.53 KB
/
Booking.java
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package STassgn;
import java.util.ArrayList;
public class Booking {
private User user;
private Room room;
private String roomType;
//to use in setBooking
private DisplayUtilities du;
//to use in cancelBooking
private Printer printer;
//to use in getting test data from file
private ArrayList<String> strList;
private int strLimit = 0;
public Booking(User user, String roomType) {
this.user = user;
this.roomType = roomType;
this.room = new Room();
this.printer = new Printer();
}
//for printer class
public String getRoomType() {
return roomType;
}
public User getUser() {
return user;
}
public void setRoom(Room room) {
this.room = room;
}
public Room getRoom() {
return room;
}
public void setDu(DisplayUtilities du) {
this.du = du;
}
// Method to set booking
public String setBooking(User user, String roomType) {
switch (roomType) {
case "VIP":
if (room.checkRoom("VIP")) {
return "VIP";
} else if (room.checkRoom("Deluxe")) {
du.showToScreen("No available VIP rooms. Booking in Deluxe room instead.\n");
return "Deluxe";
} else if (room.checkRoom("Standard")) {
du.showToScreen("No available VIP or Deluxe rooms. Booking in Standard room instead.\n");
return "Standard";
} else {
du.showToScreen("No available rooms. Adding to waiting list...\n");
return "WaitingList";
}
case "Deluxe":
if (room.checkRoom("Deluxe")) {
return "Deluxe";
} else if (room.checkRoom("Standard")) {
du.showToScreen("No available Deluxe rooms. Booking in Standard room instead.\n");
return "Standard";
} else {
du.showToScreen("No available Deluxe or Standard rooms. Adding to waiting list...\n");
return "WaitingList";
}
case "Standard":
if (room.checkRoom("Standard")) {
return "Standard";
} else {
du.showToScreen("No available Standard rooms. Adding to waiting list...\n");
return "WaitingList";
}
default:
throw new IllegalArgumentException("Invalid Room Type!");
}
}
public Booking cancelBooking(ArrayList<Booking> allBookings, DisplayUtilities du) {
// found Bookings of user
ArrayList<Booking> userBookings = new ArrayList<Booking>();
for (Booking booking : allBookings) {
if (booking.getUser().getName().equalsIgnoreCase(user.getName())) {
userBookings.add(booking);
}
}
if (userBookings.isEmpty()) {
du.showToScreen("No bookings found for " + user.getName() + "\n");
return null;
}
printer.printInfo(user, userBookings);
du.showToScreen("Are you sure you want to cancel the last booking? (Y/N): ");
String choice = du.getFromScreen();
while(!choice.equalsIgnoreCase("Y") && !choice.equalsIgnoreCase("N")) {
du.showToScreen("Invalid input. Please enter Y or N: ");
choice = du.getFromScreen();
}
if (choice.equalsIgnoreCase("Y")) {
return userBookings.get(userBookings.size() - 1);
} else {
du.showToScreen("Booking cancellation aborted.\n");
return null;
}
}
}