-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeAlphaHotelReservationSystem.java
More file actions
155 lines (113 loc) · 3.8 KB
/
Copy pathCodeAlphaHotelReservationSystem.java
File metadata and controls
155 lines (113 loc) · 3.8 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
import java.util.ArrayList;
import java.util.Scanner;
class Room {
int roomNumber;
String category;
boolean available;
Room(int roomNumber, String category) {
this.roomNumber = roomNumber;
this.category = category;
this.available = true;
}
}
class Booking {
String customerName;
int roomNumber;
Booking(String customerName, int roomNumber) {
this.customerName = customerName;
this.roomNumber = roomNumber;
}
}
public class CodeAlphaHotelReservationSystem {
static ArrayList<Room> rooms = new ArrayList<>();
static ArrayList<Booking> bookings = new ArrayList<>();
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
rooms.add(new Room(101, "Standard"));
rooms.add(new Room(102, "Standard"));
rooms.add(new Room(201, "Deluxe"));
rooms.add(new Room(202, "Deluxe"));
rooms.add(new Room(301, "Suite"));
int choice;
do {
System.out.println("\n===== HOTEL RESERVATION SYSTEM =====");
System.out.println("1. View Available Rooms");
System.out.println("2. Book Room");
System.out.println("3. Cancel Booking");
System.out.println("4. View Bookings");
System.out.println("5. Exit");
System.out.print("Enter Choice: ");
choice = sc.nextInt();
switch (choice) {
case 1:
viewRooms();
break;
case 2:
bookRoom();
break;
case 3:
cancelBooking();
break;
case 4:
viewBookings();
break;
case 5:
System.out.println("Thank You!");
break;
default:
System.out.println("Invalid Choice!");
}
} while (choice != 5);
}
static void viewRooms() {
System.out.println("\nAvailable Rooms:");
for (Room room : rooms) {
if (room.available) {
System.out.println(
room.roomNumber + " - " + room.category);
}
}
}
static void bookRoom() {
sc.nextLine();
System.out.print("Enter Customer Name: ");
String name = sc.nextLine();
System.out.print("Enter Room Number: ");
int roomNo = sc.nextInt();
for (Room room : rooms) {
if (room.roomNumber == roomNo && room.available) {
System.out.println("Payment Successful!");
room.available = false;
bookings.add(new Booking(name, roomNo));
System.out.println("Room Booked Successfully!");
return;
}
}
System.out.println("Room Not Available!");
}
static void cancelBooking() {
System.out.print("Enter Room Number to Cancel: ");
int roomNo = sc.nextInt();
for (Booking booking : bookings) {
if (booking.roomNumber == roomNo) {
bookings.remove(booking);
for (Room room : rooms) {
if (room.roomNumber == roomNo) {
room.available = true;
}
}
System.out.println("Booking Cancelled!");
return;
}
}
System.out.println("Booking Not Found!");
}
static void viewBookings() {
System.out.println("\nCurrent Bookings:");
for (Booking booking : bookings) {
System.out.println(
"Customer: " + booking.customerName +
" | Room No: " + booking.roomNumber);
}
}
}