-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
362 lines (323 loc) · 9.15 KB
/
Main.java
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
package Hotel;
import java.util.Scanner;
import java.util.InputMismatchException;
import java.util.Random;
public class Main {
public static void main(String[] args)
{
int k=0;
int n;
int m;
int nun = -1;
int a;
int fl;
//ôõ÷áéá ïíïìáôá ãéá ôéò ôõ÷áéåò êñáôçóåéò
String[] fnames = new String[20];
fnames[0]="Emma ";fnames[1]="Olivia ";
fnames[2]="Sophia ";fnames[3]="Ava ";fnames[4]="Isabel ";
fnames[5]="Mia ";fnames[6]="Emily ";fnames[7]="Anna ";fnames[8]="Alex ";
fnames[9]="Harper ";fnames[10]="Noah ";fnames[11]="Kayne ";fnames[12]="Liam ";
fnames[13]="Jacob ";fnames[14]="Ethan ";fnames[15]="Geo ";fnames[16]="Umar ";
fnames[17]="John ";fnames[18]="Zeus ";fnames[19]="Panos ";
String[] lnames = new String[20];
lnames[0]="Smith";lnames[1]="Johnson";lnames[2]="Williams";
lnames[3]="Jones";lnames[4]="Brown";lnames[5]="Davis";
lnames[6]="Miller";lnames[7]="Wilson";lnames[8]="Moore";
lnames[9]="Taylor";lnames[10]="Andreson";lnames[11]="Jackson";
lnames[12]="Lewis";lnames[13]="Thompson";lnames[14]="Garcia";
lnames[15]="Ali ";lnames[16]="Clark";lnames[17]="Chang";
lnames[18]="Obama";lnames[19]="North";
Random rand = new Random();//random number generator
Hotel hotel1 = new Hotel();
hotel1.setHotelname("Kappa Hotel");
//öôéá÷íïõìå 10 äùìáôéá áðï ïëïõò ôïõò ôõðïõò êáé ôá ðñïóèåôïõìå óôï room list
RoomTypeA roomA1 = new RoomTypeA();
roomA1.setMaxPeople(3);
roomA1.setPriceperday(45);
hotel1.addRooom(roomA1);
RoomTypeB roomB1 = new RoomTypeB();
roomB1.setMaxPeople(4);
roomB1.setPriceperday(47);
roomB1.setDiscountperday(10);
hotel1.addRooom(roomB1);
RoomTypeC roomC1 = new RoomTypeC();
roomC1.setMaxPeople(5);
roomC1.setPriceperPerson(22);
roomC1.setMinDays(2);
roomC1.setMinPeople(2);
hotel1.addRooom(roomC1);
RoomTypeD roomD1 = new RoomTypeD();
roomD1.setMaxPeople(3);
roomD1.setPriceperPerson(21);
roomD1.setPriceofRoomService(15);
hotel1.addRooom(roomD1);
RoomTypeE roomE1 = new RoomTypeE();
roomE1.setMaxPeople(6);
roomE1.setPriceperPerson(18);
hotel1.addRooom(roomE1);
RoomTypeA roomA2 = new RoomTypeA();
roomA2.setMaxPeople(2);
roomA2.setPriceperday(90);
hotel1.addRooom(roomA2);
RoomTypeB roomB2 = new RoomTypeB();
roomB2.setMaxPeople(3);
roomB2.setPriceperday(49);
roomB2.setDiscountperday(15);
hotel1.addRooom(roomB2);
RoomTypeC roomC2 = new RoomTypeC();
roomC2.setMaxPeople(4);
roomC2.setPriceperPerson(19);
roomC2.setMinDays(3);
roomC2.setMinPeople(3);
hotel1.addRooom(roomC2);
Room room1 = new Room();
room1.setMaxPeople(5);
room1.setPriceperPerson(23);
hotel1.addRooom(room1);
Room room2 = new Room();
room2.setMaxPeople(2);
room2.setPriceperPerson(15);
hotel1.addRooom(room2);
for(int i=0; ; i++)
{
while(k==0)
{
//äçìéïõñãéá ôõ÷áéáò êñáôçóçò óå ôõ÷áéï ïíïìá áðï ôá ðáñáðáíù
Reservation reservation = new Reservation();
n=rand.nextInt(fnames.length);
m=rand.nextInt(lnames.length);
reservation.setCustomer(fnames[n].concat(lnames[m]));
reservation.setArrival(rand.nextInt(30));
reservation.setResdays(rand.nextInt(31-reservation.getArrival()));
reservation.setPeople(rand.nextInt(6) + 1);
hotel1.addReservation(reservation);
int random_cancel=rand.nextInt(3);//25% ðéèáíïôçôá íá êáíåé cancel êáðïéá ôõ÷áéá êñáôçóç
if(random_cancel==1)
{
int ad=rand.nextInt(hotel1.res_list.size());
try
{
hotel1.reservationCancel(hotel1.res_list.get(ad).getRescode());
}
catch(IndexOutOfBoundsException e)
{
ad+=1;
}
}
k=1;
}
System.out.println(" 0.Rerun\n 1.Add reservation\n 2.Cancel reservation\n 3.Show reservations\n 4.Show rooms\n 5.Show Reservation Plan\n 6.Show Income\n 7.Exit ");
System.out.println("Enter 0 to 7");
Scanner scanner = new Scanner (System.in);
do//ôóåêáñåé áí ï áñéèìïò ðïõ äéíïõìå åéíáé 0-7 êáé áí äåí åéíáé îáíáæçôáåé áñéèìï
{
nun=-1;
try
{
nun = scanner.nextInt();
}
catch(InputMismatchException sd)
{
System.out.println("Selection not available.Please enter a valid number.");
scanner.nextLine();
}
}
while(nun<0);
if(nun==7)
{
break;
}
switch(nun)
{
case 0://ãéíåôáé îáíá ç ôõ÷áéá ðñïóèçêç êñáôçóçò
{
k=0;
break;
}
case 1:
{
scanner.nextLine();//êáèáñéæïõìå ôï buffer ôïõ scanner
Reservation resD = new Reservation();
System.out.println("Enter customer's first name");
String s1 = scanner.nextLine();
while(!s1.matches("[a-zA-Z]+"))//ôóåêáñåé áí ôï ïíïìá ðïõ äùóáìå å÷åé ìïíï ãñáììáôá
{
System.out.println("This is not a valid name");
s1=scanner.nextLine();
}
System.out.println("Enter customer's last name");
String s2 = scanner.nextLine();
while(!s2.matches("[a-zA-Z]+"))//ôóåêáñåé áí ôï ïíïìá ðïõ äùóáìå å÷åé ìïíï ãñáììáôá
{
System.out.println("This is not a valid name");
s2 = scanner.nextLine();
}
s1= s1+ " ";
resD.setCustomer(s1.concat(s2));
System.out.println("Customer full name is: " +resD.getCustomer());
do//ôóåêáñåé áí ï áñéèìïò ðïõ äéíïõìå åéíáé 0-29 êáé áí äåí åéíáé îáíáæçôáåé áñéèìï
{
resD.setArrival(-1);
try
{
System.out.println("Enter arrival day");
resD.setArrival(scanner.nextInt()-1);
}
catch(InputMismatchException ek)
{
System.out.println("Please insert a valid day");
scanner.nextLine();
}
}
while(resD.getArrival()<0 || resD.getArrival()>=30);
do//ôóåêáñåé áí ï áñéèìïò ðïõ äéíïõìå åéíáé 1-30 êáé áí äåí åéíáé îáíáæçôáåé áñéèìï
{
try
{
System.out.println("How many days would you like to stay?");
resD.setResdays(scanner.nextInt());
}
catch(InputMismatchException ek)
{
System.out.println("Please insert a valid number");
}
scanner.nextLine();
}
while(resD.getResdays()<=0 || resD.getResdays()>30 - resD.getArrival());
do//ôóåêáñåé áí ï áñéèìïò ðïõ äéíïõìå åéíáé èåôéêïò êáé áí äåí åéíáé îáíáæçôáåé áñéèìï
{
try
{
System.out.println("For how many people will the reservation be?");
resD.setPeople(scanner.nextInt());
}
catch(InputMismatchException ek)
{
System.out.println("Please insert a valid number");
}
scanner.nextLine();
}
while(resD.getPeople()<=0 || peps>6);
int test;
System.out.println("Would you prefer a specific room? Press 1 if you do, or else press any key");
try//ôóåêáñåé áí ôïõ äéíïõìå 1 ç ïôéäçðïôå áëëï
{
test=scanner.nextInt();
}
catch(InputMismatchException rfd)//áí äåí ôïõ äéíïõìå 1 ôïôå ôï êáíåé 0
{
test=0;
}
a=10;
if(test==1)
{
while(a<0 || a>9)
{
try//ôóåêáñåé áí ï áñéèìïò ðïõ äéíïõìå åéíáé 0-9 êáé áí äåí åéíáé îáíáæçôáåé áñéèìï
{
System.out.println("Enter room code");
a= scanner.nextInt();
}
catch(InputMismatchException uyfg)
{
System.out.println("Enter valid roomcode from 0-9");
}
scanner.nextLine();
}
hotel1.checkAddRes(resD, a);
}
else
{
hotel1.addReservation(resD);
}
break;
}
case 2:
{
fl=-1;
while(fl<0)//ôóåêáñåé áí ï áñéèìïò ðïõ äéíïõìå åéíáé áêåñáéïò êáé áí äåí åéíáé îáíáæçôáåé áñéèìï
{
try
{
System.out.println("Enter reservation code");
fl=scanner.nextInt();
hotel1.reservationCancel(fl);
}
catch(InputMismatchException uyg)
{
System.out.println("Enter valid reservation code");
}
scanner.nextLine();
}
break;
}
case 3:
{
System.out.println("Reservation code\tCustomer name\t\t\tRoom code ");
for(Reservation r : hotel1.res_list)
{
System.out.println(r.getRescode() + "\t\t\t" + r.getCustomer() + "\t\t\t" + r.room.getRoomNumber());
}
System.out.println();
break;
}
case 4:
{
System.out.println("Room code\tCompleteness\tProfit");
for(Room r1 : hotel1.room_list)
{
System.out.println(r1.getRoomNumber() + "\t\t" + r1.occpercent()+"%" + "\t\t" + r1.pricing());
}
break;
}
case 5:
{
hotel1.ResPlan();
break;
}
case 6:
{
int z=-1;
int kl;
try//ôóåêáñåé áí ôïõ äéíïõìå 1 ç ïôéäçðïôå áëëï
{
System.out.println("Would you like to enter a specific room code? If so press 1 else press any key");
kl=scanner.nextInt();
}
catch(InputMismatchException df)
{
kl=0;
}
if(kl==1)
{
while(z<0 ||z>9)
{
try//ôóåêáñåé áí ôïõ äéíïõìå 0-9 êáé áí äåí åéíáé îáíáæçôáåé áñéèìï
{
System.out.println("Enter the code");
z=scanner.nextInt();
}
catch(InputMismatchException erx)
{
System.out.println("Enter a valid code");
}
}
hotel1.findRoom(z);
hotel1.c.pricing();
System.out.println("Profit from this room is:" +hotel1.c.pricing());
}
else
{
System.out.println("Total profit is:" +hotel1.incomeCalc());
}
break;
}
default:
{
System.out.println("Selection not available.Please enter a valid number.");
break;
}
}
}
}
}