-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotel.java
More file actions
438 lines (422 loc) · 16.8 KB
/
Copy pathHotel.java
File metadata and controls
438 lines (422 loc) · 16.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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import java.util.Scanner;
import java.time.LocalDate;
class Food{
String type;
int price;
LocalDate buyOn;
Food(String type){
this.type = type;
buyOn = LocalDate.now();
if(type == "breakfast") price = 50;
else if(type == "lunch") price = 100;
else if(type == "dinner") price = 200;
else {
System.out.println("Not a valid food type.");
price = 0;
}
}
void generateBill(){
System.out.println(type + " on " + buyOn + " price: "+ price);
}
}
class Room{
int roomNo ;
int rateperday;
boolean ac ;
boolean doubleBed;
boolean available;
int bedCount;
String name;
int bookedForDays;
LocalDate checkinDate;
LocalDate checkoutDate;
Food[] foodlist = new Food[2];
int foodlistsize = 0;
Room(int rmN,int rateperday, boolean ac, boolean doubleBed, int bedCount){
this.roomNo = rmN;
this.rateperday = rateperday;
this.ac = ac;
this.doubleBed = doubleBed;
this.bedCount = bedCount;
available = true;
name = "";
}
void bookRoom(String name, int days){
this.available = false;
bookedForDays = days;
checkinDate= LocalDate.now();
checkoutDate = checkinDate.plusDays(days);
this.name = name;
}
void freeRoom(){
this.available = true;
checkoutDate = LocalDate.now();
this.name = "";
}
boolean checkAvailablility(){
if (available == true)
System.out.println("is available");
else
System.out.println("is not available");
return available;
}
void RoomDetails(){
System.out.print("Room no. " + roomNo + " is ");
if (available){
System.out.print("available having ");
if (ac){
System.out.print("AC with " + bedCount + " bed of ");
if (doubleBed){
System.out.print("double type. Rate per day = " + rateperday + "\n");
}
else{
System.out.print("single type. Rate per day = " + rateperday + "\n");
}
}
else{
System.out.print("no AC with " + bedCount + " bed of ");
if (doubleBed){
System.out.print("double type. Rate per day = " + rateperday + "\n");
}
else{
System.out.print("single type. Rate per day = " + rateperday + "\n");
}
}
}
else{
System.out.print("not available having ");
if (ac){
System.out.print("AC with " + bedCount + " bed of ");
if (doubleBed){
System.out.print("double type. Rate per day = " + rateperday +
". Name of renter: " + name+ " \n");
}
else{
System.out.print("single type. Rate per day = " + rateperday +
". Name of renter: " + name+ " \n");
}
}
else{
System.out.print("no AC with " + bedCount + " bed of ");
if (doubleBed){
System.out.print("double type. Rate per day = " + rateperday +
". Name of renter: " + name+ " \n");
}
else{
System.out.print("single type. Rate per day = " + rateperday +
". Name of renter: " + name+ " \n");
}
}
}
}
void generateBill(){
int foodTotal = 0;
for(int i=0; i<foodlistsize;i++){
foodTotal += foodlist[i].price;
}
System.out.println("--------------------------------------------");
System.out.println("Room No. : "+roomNo);
System.out.println("Booked by: "+ name);
System.out.println("check-in date: "+ checkinDate);
System.out.println("check-out date: "+checkoutDate);
System.out.println("Rent per day : "+rateperday);
for(int i=0; i<foodlistsize;i++){
foodlist[i].generateBill();
}
System.out.println("Total food amount: " + foodTotal);
System.out.println("Total Amount: "+ ((bookedForDays * rateperday)+ foodTotal));
System.out.println("--------------------------------------------");
}
void generalCheck(){
if (available == false){
if ((LocalDate.now().isEqual(checkoutDate)) || (LocalDate.now().isAfter(checkoutDate))){
System.out.println("Checkout date reached for room no. "+roomNo);
freeRoom();
}
}
}
void addFood(String type){
if (foodlistsize == foodlist.length){
Food[] newfoodlist = new Food[foodlist.length + 2];
for(int i=0; i<foodlistsize; i++){
newfoodlist[i] = foodlist[i];
}
foodlist = newfoodlist;
}
foodlist[foodlistsize] = new Food(type);
foodlistsize++;
}
}
class RoomManager{
Room rooms[] ;
int totalRooms;
Scanner sc1 = new Scanner(System.in);
RoomManager(int totalRooms){
this.totalRooms = totalRooms;
rooms =new Room[totalRooms];
for(int i=1; i<=totalRooms; i++){
rooms[i-1] = new Room(i, 0, false, false, 0);
}
}
void setRoomDetails(int rmN, int rateperday, boolean ac, boolean doubleBed, int bedCount){
for(int i=1; i<=totalRooms; i++){
if (rooms[i-1].roomNo == rmN){
rooms[i-1].rateperday = rateperday;
rooms[i-1].ac = ac;
rooms[i-1].doubleBed = doubleBed;
rooms[i-1].bedCount = bedCount;
}
}
}
void RoomsAvailability(){
boolean flag=false;
for(int i=1; i<=totalRooms;i++){
if (rooms[i-1].available){
rooms[i-1].RoomDetails();
flag = true;
}
}
if (flag == false){
System.out.println("No rooms available.");
}
System.out.println("--------------------------------------------");
}
void RoomsAvailability(boolean ac, boolean doubleBed, int bedCount){
boolean flag=false;
for(int i=1; i<=totalRooms;i++){
if (
rooms[i-1].ac == ac
&& rooms[i-1].doubleBed == doubleBed
&& rooms[i-1].bedCount == bedCount
){
if (rooms[i-1].available){
rooms[i-1].RoomDetails();
flag=true;
}
}
}
if (flag == false){
System.out.println("No rooms available with such criteria.");
}
System.out.println("--------------------------------------------");
}
void bookRoom(int roomNo){
boolean flag = false;
for(int i = 0; i<totalRooms; i++){
if ((rooms[i].roomNo==roomNo)){
flag = true;
if(rooms[i].available){
String name;
int amount=0, amount1, days;
System.out.print("Enter name of customer: ");
name = sc1.nextLine();
System.out.println("days to book for: ");
days = sc1.nextInt();
do{
System.out.print("Amount to pay is "+((rooms[i].rateperday * days) - amount)+"Rs. : ");
amount1 = sc1.nextInt();
if (amount1 ==0) break;
else amount += amount1;
if (amount < (rooms[i].rateperday * days)){
System.out.println(
"amount not sufficient. Add left money or add 0 to cancel payment.");
}
}while(amount < (rooms[i].rateperday * days));
if (amount < (rooms[i].rateperday * days)){
System.out.println(
"Room not booked due to insuffisient deposit.");
break;
}
rooms[i].bookRoom(name, days);
System.out.println("Room No. " +rooms[i].roomNo+ " booked with name: "+rooms[i].name);
}
else{
System.out.println("Room is already booked.");
}
break;
}
}
if(flag == false)System.out.println("Room no. not found.");
System.out.println("--------------------------------------------");
}
void freeRoom(int roomNo){
boolean flag = false;
for(int i=0; i<totalRooms; i++){
if (rooms[i].roomNo == roomNo){
flag = true;
if(rooms[i].available != true){
rooms[i].freeRoom();
rooms[i].generateBill();
System.out.println("Room no. "+rooms[i].roomNo+" is now available to book.");
}
else{
System.out.println("Room is already free.");
}
break;
}
}
if(flag == false) System.out.println("Room no not found.");
System.out.println("--------------------------------------------");
}
void generateBill(int roomNo){
boolean flag = false;
for(int i=0; i<totalRooms; i++){
if(rooms[i].roomNo == roomNo){
flag = true;
if(rooms[i].available){
System.out.println("--------------------------------------------");
System.out.println("Room is not booked by anyone.");
System.out.println("--------------------------------------------");
}
else
rooms[i].generateBill();
}
}
if(flag == false)
System.out.println("room not found!");
}
void generalCheck(){
for(int i=0; i<totalRooms; i++){
rooms[i].generalCheck();
}
}
void bookFood(int roomNo, String typeOfFood){
for(int i=0; i<totalRooms; i++){
rooms[i].addFood(typeOfFood);
}
}
}
class Hotel {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rooms in your hotel: ");
int totalRooms= sc.nextInt();
RoomManager manager= new RoomManager(totalRooms);
for(int i=1; i<=totalRooms; i++){
System.out.print("Enter true if room no. " +i+ " have Ac otherwise false: ");
boolean ac = sc.nextBoolean();
System.out.print("Enter true if room no. " +i+ " have double bed otherwise false: ");
boolean doubleBed = sc.nextBoolean();
System.out.print("Enter bed count for room no. " +i+": ");
int bedCount = sc.nextInt();
System.out.print("Enter rent per day for room no. " +i+": ");
int rateperday = sc.nextInt();
manager.setRoomDetails(i, rateperday, ac, doubleBed, bedCount);
System.out.println("--------------------------------------------");
}
int choose = 0;
int roomNo;
do {
manager.generalCheck();
System.out.println("1 for show all available rooms.");
System.out.println("2 for find room with custom filter");
System.out.println("3 for book room by room no.");
System.out.println("4 for free room by room no.");
System.out.println("5 for generate bill by room no.");
System.out.println("6 to book food for room no. ");
System.out.println("9 for exit menu.Any other value to reprint menu");
choose = sc.nextInt();
switch (choose) {
case 1:
manager.RoomsAvailability();
break;
case 2:
int choose2;
System.out.println("--------------------------------------------");
System.out.println("1 for non-Ac rooms with 1 bed of single type.");
System.out.println("2 for non-Ac rooms with 2 beds of single type.");
System.out.println("3 for non-Ac rooms with 1 bed of double type.");
System.out.println("4 for non-Ac rooms with 2 beds of double type.");
System.out.println("5 for Ac rooms with 1 bed of single type.");
System.out.println("6 for Ac rooms with 2 beds of single type.");
System.out.println("7 for Ac rooms with 1 bed of double type.");
System.out.println("8 for Ac rooms with 2 beds of double type.");
System.out.println("9 for custom details.");
choose2 = sc.nextInt();
switch (choose2) {
case 1:
manager.RoomsAvailability(false, false, 1);
break;
case 2:
manager.RoomsAvailability(false, false, 2);
break;
case 3:
manager.RoomsAvailability(false, true, 1);
break;
case 4:
manager.RoomsAvailability(false, true, 2);
break;
case 5:
manager.RoomsAvailability(true, false, 1);
break;
case 6:
manager.RoomsAvailability(true, false, 2);
break;
case 7:
manager.RoomsAvailability(true, true, 1);
break;
case 8:
manager.RoomsAvailability(true, true, 2);
break;
case 9:
System.out.print("enter true for ac false for non Ac: ");
boolean ac = sc.nextBoolean();
System.out.print("enter true for double bed false for single bed: ");
boolean doubleBed = sc.nextBoolean();
System.out.print("enter no of beds.");
int bedCount = sc.nextInt();
manager.RoomsAvailability(ac, doubleBed, bedCount);
break;
default:
break;
}
break;
case 3:
System.out.print("Enter room No. to book: ");
roomNo= sc.nextInt();
manager.bookRoom(roomNo);
break;
case 4:
System.out.print("Enter room No. to free: ");
roomNo = sc.nextInt();
manager.freeRoom(roomNo);
break;
case 5:
System.out.print("Enter room No. to generate bill: ");
roomNo = sc.nextInt();
manager.generateBill(roomNo);
break;
case 6:
System.out.print("Enter room No. to book food: ");
roomNo = sc.nextInt();
int choose3;
System.out.println("--------------------------------------------");
System.out.println("1 for Breakfast 50Rs.");
System.out.println("2 for Lunch 100Rs.");
System.out.println("3 for Dinner 200Rs.");
choose3 = sc.nextInt();
switch (choose3) {
case 1:
manager.bookFood(roomNo, "breakfast");
System.out.println("Breakfast booked for room no. "+ roomNo);
break;
case 2:
manager.bookFood(roomNo, "lunch");
System.out.println("Lunch booked for room no. "+ roomNo);
break;
case 3:
manager.bookFood(roomNo, "dinner");
System.out.println("Dinner booked for room no. "+ roomNo);
break;
default:
System.out.println("Not a valid food type. Food not booked.");
break;
}
default:
System.out.println("--------------------------------------------");
break;
}
} while (choose != 9);
sc.close();
}
}