-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotelReservationSystem.java
More file actions
180 lines (147 loc) · 4.81 KB
/
HotelReservationSystem.java
File metadata and controls
180 lines (147 loc) · 4.81 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
import java.util.*;
import java.util.Scanner;
class User {
private String name;
private String email;
private String phoneNumber;
public User(String name, String email, String phoneNumber) {
this.name = name;
this.email = email;
this.phoneNumber = phoneNumber;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public String getPhoneNumber() {
return phoneNumber;
}
}
class Room {
private String roomNumber;
private String roomType;
private double price;
private boolean isAvailable;
public Room(String roomNumber, String roomType, double price) {
this.roomNumber = roomNumber;
this.roomType = roomType;
this.price = price;
this.isAvailable = true;
}
public String getRoomNumber() {
return roomNumber;
}
public String getRoomType() {
return roomType;
}
public double getPrice() {
return price;
}
public boolean isAvailable() {
return isAvailable;
}
public void setAvailable(boolean available) {
this.isAvailable = available;
}
}
class Hotel {
private String name;
private List<Room> rooms;
public Hotel(String name) {
this.name = name;
this.rooms = new ArrayList<>();
}
public void addRoom(Room room) {
rooms.add(room);
}
public List<Room> findAvailableRooms(String checkIn, String checkOut) {
// Implement logic to check room availability based on check-in and check-out dates
// This would involve iterating over rooms and checking if they are available for the given period
List<Room> availableRooms = new ArrayList<>();
for (Room room : rooms) {
if (room.isAvailable()) {
availableRooms.add(room);
}
}
return availableRooms;
}
}
class Reservation {
private String reservationId;
private User guest;
private String checkIn;
private String checkOut;
private Room room;
private boolean isConfirmed;
private boolean isCancelled;
private double cancellationFee;
public Reservation(User guest, String checkIn, String checkOut, Room room, double cancellationFee) {
this.reservationId = generateReservationId();
this.guest = guest;
this.checkIn = checkIn;
this.checkOut = checkOut;
this.room = room;
this.isConfirmed = false;
this.isCancelled = false;
this.cancellationFee = cancellationFee;
}
private String generateReservationId() {
// Implement logic to generate a unique reservation ID
return "R" + System.currentTimeMillis(); // Placeholder
}
public String getReservationId() {
return reservationId;
}
public User getGuest() {
return guest;
}
public String getCheckIn() {
return checkIn;
}
public String getCheckOut() {
return checkOut;
}
public Room getRoom() {
return room;
}
public boolean isConfirmed() {
return isConfirmed;
}
public boolean isCancelled() {
return isCancelled;
}
public double getCancellationFee() {
return cancellationFee;
}
public void confirmReservation() {
isConfirmed = true;
// Send confirmation email or notification to guest
}
public void cancelReservation() {
isCancelled = true;
// Calculate and charge cancellation fee
}
}
public class HotelReservationSystem {
public static void main(String[] args) {
Hotel hotel = new Hotel("My Hotel");
hotel.addRoom(new Room("101", "Deluxe", 100.0));
hotel.addRoom(new Room("102", "Standard", 80.0));
// User interface to search for rooms, make reservations, etc.
Scanner scanner = new Scanner(System.in);
// Example usage
User user = new User("John Doe", "johndoe@example.com", "9876543210");
List<Room> availableRooms = hotel.findAvailableRooms("2024-09-01", "2024-09-05");
if (!availableRooms.isEmpty()) {
Room selectedRoom = availableRooms.get(0); // Assuming user selects first available room
Reservation reservation = new Reservation(user, "2024-09-01", "2024-09-05", selectedRoom, 50.0);
reservation.confirmReservation();
System.out.println("Reservation confirmed. Reservation ID: " + reservation.getReservationId());
} else {
System.out.println("No rooms available for the specified dates.");
}
// ... implement user interface and other functionalities
}
}