-
Notifications
You must be signed in to change notification settings - Fork 0
/
trivago.java
483 lines (480 loc) · 12.5 KB
/
trivago.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
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
//entire backend
//comments beside classes names defines what they do
import java.sql.*;
import java.util.Date;
import java.util.*;
public class trivago
{
public static void main(String[] args) {
System.out.println("Hello World");
}
}
class Register/*for new register*/
{
String name,email,address,username,password;
Date date;
Register(String name,Date date,String email,String address,String username,String password)
{
this.name=name;
this.date=date;
this.email=email;
this.address=address;
this.username=username;
this.password=password;
}
boolean register()
{
int c=0;
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/trivago?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str2="SELECT Username FROM User WHERE Username='"+username+"'";
ResultSet result=query.executeQuery(str2);
if(!result.next())
{
String str="INSERT INTO User(Name,DateOfBirth,Email,Address,Username,Password) VALUES ('"+name+"','"+date+"','"+email+"','"+address+"','"+username+"','"+password+"')";
query.executeUpdate(str);
c=1;
}
}
catch(Exception e)
{
System.out.println(e);
}
if(c==1)
return true;
else return false;
}
}
class Login/*for logining*/
{
String username,password;
int c=0;
Login(String username,String password)
{
this.username=username;
this.password=password;
}
boolean login()
{
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/trivago?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str="SELECT Username,Password FROM User WHERE Username='"+username+"'";
ResultSet result=query.executeQuery(str);
while(result.next())
{
String a=result.getString("Username");
String b=result.getString("Password");
int u=a.compareTo(username);
int p=b.compareTo(password);
if((u==0) && (p==0))
{
c=1;
break;
}
else c=0;
}
// if(c==1)
// return true;
// else return false;
}
catch(Exception e)
{
System.out.println(e);
}
if(c==1)
return true;
else return false;
}
}
//number of people should not exceed thrice the number of rooms
class Travel/*travelling details*/
{
String location;
Date checkin,checkout;
int nrooms,npeople;
Travel(String location,Date checkin,Date checkout,int nrooms,int npeople)
{
this.location=location;
this.checkin=checkin;
this.checkout=checkout;
this.nrooms=nrooms;
this.npeople=npeople;
}
boolean travel()//city selection
{
if((npeople)<(3*nrooms))
{
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/trivago?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str="INSERT INTO Travel VALUES ('"+location+"','"+checkin+"','"+checkout+"','"+nrooms+"','"+npeople+"')";
query.executeUpdate(str);
}
catch(Exception e)
{
System.out.println(e);
}
return true;
}
else return false;
}
}
class Booking//view hotels
{
String hotel,location,username;
int nrooms;
Booking(String hotel,String location,String username,int nrooms)
{
this.hotel=hotel;
this.location=location;
this.username=username;
this.nrooms=nrooms;
}
boolean booking()//view hotels
{
int k=0,z=1;
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/trivago?autoReconnect=true&useSSL=false","root","Orion@1234");
Connection con1=DriverManager.getConnection("jdbc:mysql://localhost:3306/Hotels?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
Statement query1=con1.createStatement();
String str4="SELECT Number FROM RoomA WHERE Hotel='"+hotel+"' AND Location='"+location+"'";
ResultSet result2=query1.executeQuery(str4);
while(result2.next())
{
k=result2.getInt("Number");
}
if(k>nrooms)
{
String str="SELECT Name,Email FROM User WHERE Username='"+username+"'";
ResultSet result=query.executeQuery(str);
String a="",b="";
while(result.next())
{
a=result.getString("Name");
b=result.getString("Email");
}
int c=(int)Math.random()*10;
String str1="INSERT INTO booking VALUES ('"+a+"','"+hotel+"','"+location+"','"+b+"','"+c+"','"+nrooms+"')";
query.executeUpdate(str1);
String str2="SELECT Number FROM RoomA WHERE Hotel='"+hotel+"' AND Location='"+location+"'";
ResultSet result1=query1.executeQuery(str2);
int u=0;
while(result1.next())
{
u=result1.getInt("Number");
}
u=u-nrooms;
String str3="UPDATE RoomA SET Number='"+c+"' WHERE Location='"+location+"' AND Hotel='"+hotel+"'";
query1.executeUpdate(str3);
}
else z=0;
}
catch(Exception e)
{
System.out.println(e);
}
if(z == 1)
{
return true;
}
else return false;
}
}
class Waiting//waiting list
{
String username,hotel,location;
Waiting(String username,String hotel,String location)
{
this.username=username;
this.hotel=hotel;
this.location=location;
}
String waiting()
{
int nwaitingi=0;
String nwaiting;
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/trivago?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str="SELECT Name,Email,MobileNumber FROM User WHERE Username='"+username+"'";
String str2="SELECT COUNT(*) as total FROM Waiting";
ResultSet result=query.executeQuery(str);
ResultSet result1=query.executeQuery(str2);
String a="",b="";
int c=0;
while(result.next());
{
a=result.getString("Name");
b=result.getString("Email");
c=result.getInt("MobileNumber");
}
if(result1.next())
{
nwaitingi=result1.getInt("total");
}
String str3="INSERT INTO Waiting VALUES ('"+a+"','"+location+"','"+hotel+"','"+b+"','"+c+"')";
query.executeUpdate(str3);
}
catch(Exception e)
{
System.out.println(e);
}
nwaiting=String.valueOf(nwaitingi);
return nwaiting;
}
}
class Hotel/*includes hotels,room availability,facilities*/
{
/*String[] hotel()
{
String details[]=new String[100];
String hotel="",location="";
int i=0;
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Hotels?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str="SELECT * FROM Hotel";
ResultSet result=query.executeQuery(str);
while(result.next())
{
hotel=result.getString("Hotel");
location=result.getString("Location");
details[i]=hotel;
details[i+1]=location;
i++;
}
}
catch(Exception e)
{
System.out.println(e);
}
return details;
}*/
String[] room()//room details new bookings->travel->s
{
String rdetails[]=new String[100];
String price="",hotel="";
int i=0;
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Hotels?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str="SELECT Hotel,Location,Price FROM RoomA";
ResultSet result=query.executeQuery(str);
while(result.next())
{
hotel=result.getString("Hotel");
price=result.getString("Price");
rdetails[i]=hotel;
rdetails[i+1]=price;
}
}
catch(Exception e)
{
System.out.println(e);
}
return rdetails;
}
// boolean[] cfacilities(String hotel,String location)
// {
// boolean comp[]=new boolean[100];
// boolean wifi,tv,hwater,kettle,satchets;
// int i=0;
// try
// {
// Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Facilities?autoReconnect=true&useSSL=false","root","Orion@1234");
// Statement query=con.createStatement();
// String str="SELECT * FROM Comp WHERE Hotel='"+hotel+"' AND Location='"+location+"'";
// ResultSet result=query.executeQuery(str);
// while(result.next());
// {
// wifi=result.getBoolean("Wifi");
// tv=result.getBoolean("TV");
// hwater=result.getBoolean("HWater");
// kettle=result.getBoolean("Kettle");
// satchets=result.getBoolean("Satchets");
// comp[i]=wifi;
// comp[i+1]=tv;
// comp[i+2]=hwater;
// comp[i+3]=kettle;
// comp[i+4]=satchets;
// i++;
// }
// }
// catch(Exception e)
// {
// System.out.println(e);
// }
// return comp;
// }
// boolean[] pfacilities(String hotel,String location)
// {
// boolean paid[]=new boolean[100];
// boolean meals,laundry,crental,swimming,gym,jaccuzi;
// int i=0;
// try
// {
// Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Facilities?autoReconnect=true&useSSL=false","root","Orion@1234");
// Statement query=con.createStatement();
// String str="SELECT * FROM Paid WHERE Hotel='"+hotel+"' AND Location='"+location+"'";
// ResultSet result=query.executeQuery(str);
// while(result.next())
// {
// meals=result.getBoolean("3Meals");
// laundry=result.getBoolean("Laundry");
// crental=result.getBoolean("CRental");
// swimming=result.getBoolean("Swimming");
// gym=result.getBoolean("Gym");
// jaccuzi=result.getBoolean("Jaccuzi");
// paid[i]=meals;
// paid[i+1]=laundry;
// paid[i+2]=crental;
// paid[i+3]=swimming;
// paid[i+4]=gym;
// paid[i+5]=jaccuzi;
// i++;
// }
// }
// catch(Exception e)
// {
// System.out.println(e);
// }
// return paid;
// }
boolean[] finalf(String hotel,String location)
{
boolean fac[]=new boolean[100];
boolean ac,wifi,parking,tv,card,elevator,dining,netflix,swimming;
int i=0;
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Facilities?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str="SELECT * FROM final WHERE Hotel='"+hotel+"' AND Location='"+location+"'";
ResultSet result=query.executeQuery(str);
while(result.next())
{
ac=result.getBoolean("AC");
wifi=result.getBoolean("Wifi");
parking=result.getBoolean("Parking");
tv=result.getBoolean("TV");
elevator=result.getBoolean("Elevator");
dining=result.getBoolean("Dining");
netflix=result.getBoolean("Netflix");
swimming=result.getBoolean("Swimming");
fac[i]=ac;
fac[i+1]=wifi;
fac[i+2]=parking;
fac[i+3]=tv;
fac[i+4]=elevator;
fac[i+5]=dining;
fac[i+6]=netflix;
fac[i+7]=swimming;
i++;
}
}
catch(Exception e)
{
System.out.println(e);
}
return fac;
}
String[] ratings(String hotel,String location)
{
int nfeedbacki=0,ratingi=0;
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Hotels?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str="SELECT AVG(Ratings) as ratings FROM Ratings WHERE Hotel='"+hotel+"' AND Location='"+location+"'";
String str1="SELECT COUNT(Feedback) as total FROM Ratings WHERE Hotel='"+hotel+"' AND Location='"+location+"'";
ResultSet result=query.executeQuery(str);
ResultSet result1=query.executeQuery(str1);
while(result.next())
{
ratingi=result.getInt("ratings");
}
if(result1.next())
{
nfeedbacki=result1.getInt("total");
}
}
catch(Exception e)
{
System.out.println(e);
}
String rating=String.valueOf(ratingi);
String nfeedback=String.valueOf(nfeedbacki);
String feedback[]=new String[2];
feedback[0]=rating;feedback[1]=nfeedback;
return feedback;
}
}
class CancelBooking//cancellation
{
String username;
int brnumber;//booking reference number
CancelBooking(String username,int brnumber)
{
this.username=username;
this.brnumber=brnumber;
}
boolean cancel()
{
int x=0;
try
{
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/trivago?autoReconnect=true&useSSL=false","root","Orion@1234");
Statement query=con.createStatement();
String str="SELECT * FROM booking WHERE ReferenceNo='"+brnumber+"'";
ResultSet result =query.executeQuery(str);
if(result.next())
{
String str1="DELETE FROM booking WHERE ReferenceNo='"+brnumber+"'";
query.executeUpdate(str1);
x=1;
}
else x=0;
}
catch(Exception e)
{
System.out.println(e);
}
if(x == 1)
return true;
else return false;
}
}
//to verify pan and aadhar number
class Verify
{
int aadhar;
String pan;
Verify(int aadhar,String pan)
{
this.aadhar=aadhar;
this.pan=pan;
}
boolean verify()
{
int lp=pan.length();
int la=(int)(Math.log10(aadhar)+1);
if((lp == 0) &&(la == 0))
return false;
else
{
if((lp == 10) || (la == 12))
return true;
else return false;
}
}
}