-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
524 lines (480 loc) · 19.3 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
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
package playground;
import java.io.*;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
/*
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;*/
class Program {
static List<Client> clients = new ArrayList<Client>();
static int connectedClient;
static List<playground.PG> PG = new ArrayList<playground.PG>();
static List<playground.BookPG> bookPG = new ArrayList<playground.BookPG>();
static List<playground.Payment> payment = new ArrayList<playground.Payment>();
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
mainMenu();
while(true) {
System.out.println(clients.get(connectedClient).ClientType);
switch(clients.get(connectedClient).ClientType) {
case 1:
BookingPlayground();
break;
case 2:
creatingPlayground();
break;
case 3:
AdminMenu();
break;
}
}
}
public static void mainMenu()
{
String email=""; String password; String name; int accType;
int option; int flag=0;
while (flag==0) {
System.out.println("Hello in Playgrounds reservation system please enter your choice: ");
System.out.println("1) Sign in");
System.out.println("2) Register");
option = scanner.nextInt();
switch(option) {
case 1:
System.out.println("Enter your email");
email = scanner.next();
System.out.println("Enter your password");
password = scanner.next();
if(verifyClient(email, password)) {
flag =1;
continue;
/*System.out.println("Welcome " + clients.get(connectedClient).Name);
if(!clients.get(connectedClient).verified) {
System.out.println("Enter your Verification Code");
int vf = scanner.nextInt();
clients.get(connectedClient).verify(vf);
}*/
}
else {
System.out.println("Invalid username or password");
for(int i=0;i<clients.size();i++)
System.out.println(clients.get(i).Email + clients.get(i).Password);
}
break;
case 2:
System.out.println("Enter your email");
email = scanner.next();
System.out.println("Enter your name");
name = scanner.next();
System.out.println("Enter your password");
password = scanner.next();
System.out.println("choose account type");
System.out.println("1- Player");
System.out.println("2- Playground Owner");
System.out.println("3- Adminstrator");
accType = scanner.nextInt();
int vf = GenerateVerificationCode();
clients.add(new Client(email, password,name, vf, accType));
//AddClient(email, name, password,accType);
break;
}
}
}
public static String createPGid(int idscount) {
int id;
id = idscount + 1;
return String.valueOf(id);
}
public static void creatingPlayground() {
String PGid;
String name;
String PGdescription;
String address;
int pricehour;
int bookingNo;
Boolean approved;
String[][] Avilablehours = new String[24][2];
String state = "";
String ownerid = "";
int optionowner;
int idscount = 0;
System.out.println("Hello in Playgrounds reservation system please enter your choice: ");
System.out.println("1) Add playground. ");
System.out.println("2) Sign Out ");
optionowner = scanner.nextInt();
switch (optionowner) {
case 2:
mainMenu();
break;
case 1:
PGid = createPGid(idscount);
idscount++;
System.out.println("Enter Playground name: ");
name = scanner.next();
System.out.println("Enter Playground description: ");
PGdescription = scanner.next();
System.out.println("Enter Playground address: ");
address = scanner.next();
System.out.println("Enter Playground price hour: ");
pricehour = scanner.nextInt();
String hour = "00:00";
for (int i = 0; i < 24; i++) {
Avilablehours[i][0] = String.valueOf(hour);
hour = String.valueOf(LocalTime.parse(hour).plusHours(1));
}
for (int i = 0; i < 24; i++) {
Avilablehours[i][1] = "A";
}
PG.add(new PG(PGid, name, PGdescription, address, pricehour, 0, false, Avilablehours, state, ownerid));
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 2; j++) {
System.out.println(PG.get(0).Avilablehours[i][j]);
}
}
break;
}
}
public static String createBPGid(int idbookcount) {
int id;
id = idbookcount + 1;
return String.valueOf(id);
}
public static void BookingPlayground(){
String id;
String playgroundid;
String accountid = "0";
String date;
String total;
String description;
String starthour;
String duration;
String paymentid;
int optionplayer;
int idbookcount = 0;
System.out.println("Hello in Playgrounds reservation system please enter your choice: ");
System.out.println("1) Book a playground. ");
System.out.println("2) Complaint on a playground.");
System.out.println("3) Create a team.");
System.out.println("4) Sign Out ");
optionplayer = scanner.nextInt();
int Coption;
String complaint;
switch (optionplayer) {
case 4:
mainMenu();
break;
case 1:
for (int i = 0; i < PG.size(); i++) {
if (PG.get(i).approved == true){
System.out.println((i + 1) + ") " + PG.get(i).name);
}
else{
System.out.println("No playgrounds Exist");
}
}
break;
case 2:
ViewingPlaygrounds();
System.out.println("Enter playground number:");
Coption = scanner.nextInt();
System.out.println("Enter your complaint:");
complaint = scanner.next();
for (int j = 0; j < Coption; j++) {
PG.get(j).ComplaintsN++;
PG.get(j).Complaints.add(complaint);
}
case 3:
CreatingTeam();
break;
}
if(optionplayer==1) {
int optionbook;
optionbook = scanner.nextInt();
/*for (int i = 0; i < 24; i++) {
if (PG.get(optionbook).Avilablehours[i][1] == "A")
System.out.println(PG.get(optionbook).Avilablehours[i][0]);
}*/
System.out.println("Do you want to reserve? (Y/N) ");
String answer = scanner.next();
if (answer.equalsIgnoreCase("Y")) {
int fromhour;
int tohour;
System.out.println("The slot you want is from? (ex:12,7,23) ");
fromhour = scanner.nextInt();
System.out.println("The slot you want is to? (ex:13,8,0) ");
tohour = scanner.nextInt();
System.out.println("Enter the description: ");
description = scanner.next();
starthour = String.valueOf(fromhour);
id = createBPGid(idbookcount);
playgroundid = PG.get(optionbook-1).id;
//accountid
date = String.valueOf(LocalDate.now());
duration = String.valueOf(tohour - fromhour);
total = String.valueOf((tohour - fromhour) * (PG.get(optionbook-1).pricehour));
paymentid = "1";//payment.get(optionbook-1).id;
bookPG.add(new BookPG(id, playgroundid, Integer.toString(clients.get(connectedClient).ClientId), date, total, description, starthour, duration, paymentid));
for (int i = fromhour; i < tohour; i++) {
PG.set(optionbook-1, null).Avilablehours[i][1] = "B";
}
}
}
}
public static void AdminMenu() {
int option;
System.out.println("Hello in Playgrounds reservation system please enter your choice: ");
System.out.println("1) Approve a playground. ");
System.out.println("2) Filter playgrounds.");
System.out.println("3) Sign Out ");
option = scanner.nextInt();
switch(option)
{
case 3:
mainMenu();
break;
case 1:
ApprovingRequests();
break;
case 2:
FilteringPlaygrounds();
break;
}
}
public static void ApprovingRequests() {
if (PG.size() == 0) {
System.out.println("There are no Playgrounds in the system");
} else {
System.out.println("Requested Playgrounds: *Playgrounds Appear sequentially");
System.out.println("");
String choice;
for (int i = 0; i < PG.size(); i++) {
if (PG.get(i).approved == false) {
System.out.println((i + 1) + ") ");
System.out.println("Name: " + PG.get(i).name);
System.out.println("ID: " + PG.get(i).id);
System.out.println("Address: " + PG.get(i).address);
System.out.println("Description: " + PG.get(i).description);
System.out.println("");
System.out.println("Enter 'A' to approve playground or 'R' to reject Playground.");
choice = scanner.next();
switch (choice) {
case "A":
PG.get(i).approved = true;
break;
case "R":
PG.remove(i);
break;
}
}
}
}
}
public static void ViewingPlaygrounds() {
for (int i = 0; i < PG.size(); i++) {
if (PG.get(i).approved == true) {
System.out.println((i + 1) + ") ");
System.out.println("Name: " + PG.get(i).name);
System.out.println("ID: " + PG.get(i).id);
System.out.println("Address: " + PG.get(i).address);
System.out.println("Description: " + PG.get(i).description);
System.out.println("Number of complaints: " + PG.get(i).ComplaintsN);
}
}
}
public static void FilteringPlaygrounds() {
String Input;
String Choice;
System.out.println("Enter Playground name or id");
Input = scanner.next();
for (int i = 0; i < PG.size(); i++) {
if (PG.get(i).name == Input || PG.get(i).id == Input) {
System.out.println((i + 1) + ") ");
System.out.println("Address: " + PG.get(i).address);
System.out.println("Number of complaints: " + PG.get(i).ComplaintsN);
System.out.println("Complaints: ");
for (int j = 0; j < PG.get(i).Complaints.size(); j++) {
System.out.println(PG.get(i).Complaints.get(j));
}
System.out.println(" ");
System.out.println("Do you wanna remove this playground (Y or N) ");
Choice=scanner.next();
while (Choice!="Y" || Choice!="N"){
System.out.println("Invalid input, Enter Y or N");
Choice=scanner.next();
}
if(Choice=="Y")
PG.remove(i);
}
}
}
public static void CreatingTeam() {
int TeamNumber;
String name = "", Gmail = "", playerID = "", playerName = "", playgroundID = "", playgroundName = "", matchTime = "";
System.out.println("Enter your team number *includes you*");
TeamNumber = scanner.nextInt();
while (TeamNumber != 5) {
System.out.println("Invalid input, Your must should contains 5 players");
System.out.println("Enter valid number");
TeamNumber = scanner.nextInt();
}
playerName = clients.get(connectedClient).Name;
playerID = Integer.toString(clients.get(connectedClient).ClientId);
for (int j = 0; j < bookPG.size(); j++) {
if (bookPG.get(j).accountid == playerID) {
playgroundID = bookPG.get(j).playgroundid;
matchTime = bookPG.get(j).starthour;
}
}
for (int x = 0; x < PG.size(); x++) {
if (PG.get(x).id == playgroundID)
playgroundName = PG.get(x).name;
}
for (int i = 0; i < 5; i++) {
System.out.println("Enter player (" + (i + 1) + ")'s name: ");
name = scanner.next();
System.out.println("Enter player (" + (i + 1) + ")'s gmail: ");
Gmail = scanner.next();
// sendEmailForTeam(name, Gmail, playerName, playgroundName, matchTime);
}
}
public static void AddClient(String email, String name, String password, int accType)
{
File file = new File(System.getProperty("user.dir") + "/emails.txt");
try {
file.createNewFile();
FileWriter fw = new FileWriter(file,true);
int vf = GenerateVerificationCode();
//sendEmail(email, vf);
Writer bw = new BufferedWriter(fw);
bw.append(email + "\n" + name + "\n" + password + "\n" + vf + "\n" + accType + "\n");
bw.flush();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static int GenerateVerificationCode() {
Random rand = new Random();
int upperbound = 10000;
int int_random = rand.nextInt(upperbound);
return int_random;
}
public static void LoadUsers() {
File file = new File(System.getProperty("user.dir") + "/emails.txt");
BufferedReader br = null;
try {
file.createNewFile();
br = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
System.out.println(e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String st;
String ml = "";
String nm = "";
String pass = "";
int accType = 0;
int vf=0;
int i = 0;
try {
while ((st = br.readLine()) != null) {
if (i == 0) {
ml = st;
i++;
} else if (i == 1) {
nm = st;
i++;
}
else if (i == 2) {
pass = st;
i++;
}
else if (i == 3) {
vf = Integer.parseInt(st);
i++;
}
else {
accType = Integer.parseInt(st);
System.out.println(accType);
clients.add(new Client(ml, pass, nm, vf, accType));
i = 0;
}
}
} catch (IOException e) {
System.out.println(e);
}
}
public static boolean verifyClient(String email, String password) {
for (int i = 0; i < clients.size(); i++) {
if (email.equalsIgnoreCase(clients.get(i).Email)) {
if (password.equalsIgnoreCase(clients.get(i).Password)) {
connectedClient = i;
return true;
}
}
}
return false;
}
/* public static void sendEmail(String to, int vf){
String from = "";
String password = "";
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
//get Session
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from,password);
}
});
//compose message
try {
MimeMessage message = new MimeMessage(session);
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Playground Reservation System");
message.setText("Your verification code is " + vf);
//send message
Transport.send(message);
System.out.println("message sent successfully");
} catch (MessagingException e) {throw new RuntimeException(e);}
}
public static void sendEmailForTeam(String toName,String toMail, String by, String in, String at){
String from = "";
String password = "";
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
//get Session
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from,password);
}
});
//compose message
try {
MimeMessage message = new MimeMessage(session);
message.addRecipient(Message.RecipientType.TO,new InternetAddress(toMail));
message.setSubject("Playground Reservation System");
message.setText("Hi "+toName+", Your friend: '" +by+"' "+"booked a match in playground: '"+in+"' "+"at time:'"+at+"' "+"Make sure to be there");
//send message
Transport.send(message);
System.out.println("message sent successfully");
} catch (MessagingException e) {throw new RuntimeException(e);}
}*/
}