- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotelReservationSystem.java
More file actions
Latest commit
300 lines (248 loc) · 12.2 KB
/
Copy pathHotelReservationSystem.java
File metadata and controls
300 lines (248 loc) · 12.2 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// Name Shayan ADil Khan
// id : CA/S1/9549
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.util.HashMap;
importjava.util.Map;
publicclassHotelReservationSystem {
privatestaticfinalMap<String, Room> rooms = newHashMap<>();
privatestaticfinalMap<String, Booking> bookings = newHashMap<>();
publicstaticvoidmain(String[] args) {
// Sample room data
rooms.put("101", newRoom("101", "Single", 100.0, true));
rooms.put("102", newRoom("102", "Double", 150.0, true));
rooms.put("103", newRoom("103", "Suite", 250.0, false));
rooms.put("104", newRoom("104", "Single", 100.0, true));
rooms.put("105", newRoom("105", "Double", 150.0, true));
rooms.put("106", newRoom("106", "Suite", 250.0, true));
rooms.put("107", newRoom("107", "Single", 100.0, true));
rooms.put("108", newRoom("108", "Double", 150.0, true));
rooms.put("109", newRoom("109", "Suite", 250.0, true));
rooms.put("110", newRoom("110", "Single", 100.0, true));
SwingUtilities.invokeLater(() -> {
JFrameframe = newJFrame("Hotel Reservation System");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1000, 700); // Increased size of the frame
frame.add(newMainPanel());
frame.setVisible(true);
});
}
staticclassMainPanelextendsJPanel {
privateCardLayoutcardLayout;
privateJPanelcardPanel;
privateJTextAreadetailsArea;
privateJTextFieldsearchRoomField;
privateJTextFieldnameField;
privateJTextFieldroomField;
privateJTextFieldpaymentField;
publicMainPanel() {
setLayout(newBorderLayout());
setBackground(newColor(144, 238, 144)); // Light green background color
// Adding the label with your name and ID
JLabelheaderLabel = newJLabel("Shayan Adil Khan ID: CA/S1/9549", SwingConstants.CENTER);
headerLabel.setFont(newFont("Arial", Font.BOLD, 20));
headerLabel.setForeground(Color.BLACK);
add(headerLabel, BorderLayout.NORTH);
cardLayout = newCardLayout();
cardPanel = newJPanel(cardLayout);
cardPanel.add(createSearchPanel(), "Search");
cardPanel.add(createReservationPanel(), "Reserve");
cardPanel.add(createBookingDetailsPanel(), "Details");
add(cardPanel, BorderLayout.CENTER);
JPanelbuttonPanel = newJPanel();
buttonPanel.setBackground(newColor(144, 238, 144)); // Light green for button panel
JButtonsearchButton = createStyledButton("Search Rooms");
JButtonreserveButton = createStyledButton("Make Reservation");
JButtondetailsButton = createStyledButton("Booking Details");
searchButton.addActionListener(e -> cardLayout.show(cardPanel, "Search"));
reserveButton.addActionListener(e -> cardLayout.show(cardPanel, "Reserve"));
detailsButton.addActionListener(e -> cardLayout.show(cardPanel, "Details"));
buttonPanel.add(searchButton);
buttonPanel.add(reserveButton);
buttonPanel.add(detailsButton);
add(buttonPanel, BorderLayout.SOUTH); // Changed to SOUTH to avoid overlapping with the header label
}
privateJButtoncreateStyledButton(Stringtext) {
JButtonbutton = newJButton(text);
button.setBackground(Color.DARK_GRAY);
button.setForeground(Color.WHITE);
button.setFocusPainted(false);
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
button.setPreferredSize(newDimension(150, 40));
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
// Add a hover effect
button.addMouseListener(newjava.awt.event.MouseAdapter() {
@Override
publicvoidmouseEntered(java.awt.event.MouseEventevt) {
button.setBackground(Color.GRAY);
}
@Override
publicvoidmouseExited(java.awt.event.MouseEventevt) {
button.setBackground(Color.DARK_GRAY);
}
});
returnbutton;
}
privateJPanelcreateSearchPanel() {
JPanelpanel = newJPanel();
panel.setLayout(newBorderLayout());
searchRoomField = newJTextField(20); // Increased length of the search field
searchRoomField.setFont(newFont("Arial", Font.BOLD, 16)); // Bold and increased font size
JLabelsearchLabel = newJLabel("Enter Room Number:");
searchLabel.setFont(newFont("Arial", Font.BOLD, 16)); // Bold and increased font size
JButtonsearchButton = createStyledButton("Search");
searchButton.addActionListener(newSearchButtonListener());
JPanelinputPanel = newJPanel();
inputPanel.add(searchLabel); // Label for input
inputPanel.add(searchRoomField); // Adding text field to input panel
inputPanel.add(searchButton); // Adding button to input panel
detailsArea = newJTextArea(15, 50);
detailsArea.setEditable(false);
detailsArea.setFont(newFont("Arial", Font.PLAIN, 16)); // Increased font size for details
panel.add(inputPanel, BorderLayout.NORTH); // Add input panel to the top of the search panel
panel.add(newJScrollPane(detailsArea), BorderLayout.CENTER); // Add details area to the center
returnpanel;
}
privateJPanelcreateReservationPanel() {
JPanelpanel = newJPanel();
panel.setLayout(newGridLayout(5, 2));
JLabelnameLabel = newJLabel("Name:");
nameLabel.setFont(newFont("Arial", Font.BOLD, 16)); // Bold and increased font size
panel.add(nameLabel);
nameField = newJTextField();
nameField.setFont(newFont("Arial", Font.BOLD, 16)); // Bold and increased font size
panel.add(nameField);
JLabelroomLabel = newJLabel("Room Number:");
roomLabel.setFont(newFont("Arial", Font.BOLD, 16)); // Bold and increased font size
panel.add(roomLabel);
roomField = newJTextField();
roomField.setFont(newFont("Arial", Font.BOLD, 16)); // Bold and increased font size
panel.add(roomField);
JLabelpaymentLabel = newJLabel("Payment Amount:");
paymentLabel.setFont(newFont("Arial", Font.BOLD, 16)); // Bold and increased font size
panel.add(paymentLabel);
paymentField = newJTextField();
paymentField.setFont(newFont("Arial", Font.BOLD, 16)); // Bold and increased font size
panel.add(paymentField);
JButtonreserveButton = createStyledButton("Reserve");
reserveButton.addActionListener(newReserveButtonListener());
panel.add(reserveButton);
returnpanel;
}
privateJPanelcreateBookingDetailsPanel() {
JPanelpanel = newJPanel();
panel.setLayout(newBorderLayout());
JTextAreabookingDetailsArea = newJTextArea(15, 50);
bookingDetailsArea.setEditable(false);
bookingDetailsArea.setFont(newFont("Arial", Font.PLAIN, 16)); // Increased font size for booking details
panel.add(newJScrollPane(bookingDetailsArea), BorderLayout.CENTER);
JButtonrefreshButton = createStyledButton("Refresh");
refreshButton.addActionListener(e -> {
StringBuildersb = newStringBuilder();
for (Map.Entry<String, Booking> entry : bookings.entrySet()) {
sb.append("Booking ID: ").append(entry.getKey()).append("\n")
.append("Name: ").append(entry.getValue().getName()).append("\n")
.append("Room Number: ").append(entry.getValue().getRoomNumber()).append("\n")
.append("Amount Paid: $").append(entry.getValue().getAmountPaid()).append("\n")
.append("--------\n");
}
bookingDetailsArea.setText(sb.toString());
});
panel.add(refreshButton, BorderLayout.SOUTH);
returnpanel;
}
privateclassSearchButtonListenerimplementsActionListener {
@Override
publicvoidactionPerformed(ActionEvente) {
StringroomNumber = searchRoomField.getText();
Roomroom = rooms.get(roomNumber);
if (room != null) {
detailsArea.setText("Room Number: " + room.getNumber() + "\n" +
"Category: " + room.getCategory() + "\n" +
"Price: $" + room.getPrice() + "\n" +
"Available: " + (room.isAvailable() ? "Yes" : "No"));
} else {
detailsArea.setText("Room not found.");
}
}
}
privateclassReserveButtonListenerimplementsActionListener {
@Override
publicvoidactionPerformed(ActionEvente) {
Stringname = nameField.getText();
StringroomNumber = roomField.getText();
StringpaymentAmount = paymentField.getText();
Roomroom = rooms.get(roomNumber);
if (room != null) {
if (room.isAvailable()) {
doubleamount;
try {
amount = Double.parseDouble(paymentAmount);
} catch (NumberFormatExceptionex) {
JOptionPane.showMessageDialog(null, "Invalid payment amount.");
return;
}
bookings.put(roomNumber, newBooking(name, roomNumber, amount));
room.setAvailable(false);
JOptionPane.showMessageDialog(null, "Reservation successful.");
nameField.setText("");
roomField.setText("");
paymentField.setText("");
} else {
JOptionPane.showMessageDialog(null, "Room is not available.");
}
} else {
JOptionPane.showMessageDialog(null, "Room not found.");
}
}
}
}
staticclassRoom {
privateStringnumber;
privateStringcategory;
privatedoubleprice;
privatebooleanavailable;
publicRoom(Stringnumber, Stringcategory, doubleprice, booleanavailable) {
this.number = number;
this.category = category;
this.price = price;
this.available = available;
}
publicStringgetNumber() {
returnnumber;
}
publicStringgetCategory() {
returncategory;
}
publicdoublegetPrice() {
returnprice;
}
publicbooleanisAvailable() {
returnavailable;
}
publicvoidsetAvailable(booleanavailable) {
this.available = available;
}
}
staticclassBooking {
privateStringname;
privateStringroomNumber;
privatedoubleamountPaid;
publicBooking(Stringname, StringroomNumber, doubleamountPaid) {
this.name = name;
this.roomNumber = roomNumber;
this.amountPaid = amountPaid;
}
publicStringgetName() {
returnname;
}
publicStringgetRoomNumber() {
returnroomNumber;
}
publicdoublegetAmountPaid() {
returnamountPaid;
}
}
}