-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode
More file actions
165 lines (133 loc) · 4.74 KB
/
Copy pathCode
File metadata and controls
165 lines (133 loc) · 4.74 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
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class HotelReservationSystem {
private static Map<String, Room> rooms = new HashMap<>();
private static Map<String, Reservation> reservations = new HashMap<>();
private static int reservationIdCounter = 1;
public static void main(String[] args) {
initializeRooms();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("\nMariam's Hotel Reservation System");
System.out.println("Type 1 To Search For Available Rooms");
System.out.println("Type 2 To Make a Reservation");
System.out.println("Type 3 To View Booking Details");
System.out.println("Type 4 To Exit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
searchAvailableRooms();
break;
case 2:
makeReservation(scanner);
break;
case 3:
viewBookingDetails(scanner);
break;
case 4:
System.out.println("Thank you for using the Hotel Reservation System. Goodbye!");
scanner.close();
System.exit(0);
default:
System.out.println("Invalid choice. Please choose a valid option.");
}
}
}
private static void initializeRooms() {
rooms.put("101", new Room("101", "Single", 50.0));
rooms.put("102", new Room("102", "Double", 75.0));
rooms.put("103", new Room("103", "Suite", 100.0));
}
private static void searchAvailableRooms() {
System.out.println("Available Rooms:");
for (Room room : rooms.values()) {
if (!room.isReserved()) {
System.out.println(room);
}
}
}
private static void makeReservation(Scanner scanner) {
System.out.print("Enter the room number to reserve: ");
String roomNumber = scanner.next();
Room selectedRoom = rooms.get(roomNumber);
if (selectedRoom != null && !selectedRoom.isReserved()) {
System.out.print("Enter your good name: ");
String guestName = scanner.next();
Reservation reservation = new Reservation(reservationIdCounter++, guestName, selectedRoom);
reservations.put(String.valueOf(reservation.getReservationId()), reservation);
selectedRoom.setReserved(true);
System.out.println("Reservation successful. Your reservation ID is: " + reservation.getReservationId());
} else {
System.out.println("Invalid room number or the room is already reserved. Please try again.");
}
}
private static void viewBookingDetails(Scanner scanner) {
System.out.print("Enter your reservation ID: ");
int reservationId = scanner.nextInt();
Reservation reservation = reservations.get(Integer.toString(reservationId));
if (reservation != null) {
System.out.println("\nBooking Details:");
System.out.println(reservation);
} else {
System.out.println("Invalid reservation ID. Please try again.");
}
}
}
class Room {
private String number;
private String type;
private double price;
private boolean reserved;
public Room(String number, String type, double price) {
this.number = number;
this.type = type;
this.price = price;
this.reserved = false;
}
public String getNumber() {
return number;
}
public String getType() {
return type;
}
public double getPrice() {
return price;
}
public boolean isReserved() {
return reserved;
}
public void setReserved(boolean reserved) {
this.reserved = reserved;
}
@Override
public String toString() {
return "Room " + number + " - " + type + " - $" + price + " per night";
}
}
class Reservation {
private int reservationId;
private String guestName;
private Room room;
public Reservation(int reservationId, String guestName, Room room) {
this.reservationId = reservationId;
this.guestName = guestName;
this.room = room;
}
public int getReservationId() {
return reservationId;
}
public String getGuestName() {
return guestName;
}
public Room getRoom() {
return room;
}
@Override
public String toString() {
return "Reservation ID: " + reservationId +
"\nGuest Name: " + guestName +
"\nRoom: " + room +
"\nTotal Price: $" + room.getPrice();
}
}