-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaUserCommandLine.java
More file actions
795 lines (639 loc) · 33.5 KB
/
JavaUserCommandLine.java
File metadata and controls
795 lines (639 loc) · 33.5 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
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
import javax.imageio.ImageIO;
import javax.swing.text.Style;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.Socket;
import java.net.UnknownHostException;
import java.time.*;
import java.util.*;
import java.io.*;
import java.util.Timer;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
//Java User CommandLine Class
public class JavaUserCommandLine {
public static void main(String[] args) throws IOException, InterruptedException {
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
//Logo to be animated
String[] Logo={"M","A","T","H"," ","M","A","S","T","E","R"," ","S","Y","S","T","E","M"," ","O","P","E","N","E","D","!"};
System.out.println("\n");
//the for loop to simulate animation
for(int i=0;i<26;i++){
System.out.print(Yellow+Italic+Logo[i]);
try {
Thread.sleep(100);//thread to simulate processing
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.print(Restore);
System.out.println("\n");
int Counter = 0;//passed on to keep track of invalid option user inputs time, not to exceed two times
UserInterface Interface = new UserInterface();
Interface.processCommand(Counter);
System.out.println("\n\n");
//animates the string at the close of the system
endOfSystem();
}
//animate Logo at when closing the system
public static void endOfSystem(){
// text to be animated
String[] Logo={"M","A","T","H"," ","M","A","S","T","E","R"," ","S","Y","S","T","E","M"," ","C","L","O","S","E","D","!"};
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
//the for loop to simulate animation
for(int i=0;i<26;i++){
System.out.print(Yellow+Italic+Logo[i]);
try {
Thread.sleep(100);//thread to simulate processing
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.print(Restore);
}
}
// Question class
//Challenge class
//User class
//School Representative class and it's methods
class SchoolRep extends User {
//for viewing challenges after logging in
public void viewChallenge() {
System.out.println("view challenge");
}
//for viewing applicants on a particular school from the java file
public void viewApplicant(ObjectInputStream OIS, ObjectOutputStream OOS, int Counter, String Command) {
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
ArrayList<PupilToFile> pupilToFiles = new ArrayList<>();
try {
//sending request to the server
OOS.writeObject(Command);
//error catch
if (Counter == 1) {
System.err.print(" ONE MORE TRIAL REMAINING......\n\n");
Thread.sleep(1000);
}
//listening for the servers response
pupilToFiles = (ArrayList<PupilToFile>) OIS.readObject();
if (pupilToFiles.isEmpty()) {
System.err.println("-----No Applicants Yet!-----");
Thread.sleep(100);
} else {
Iterator<PupilToFile> pupilToFileIterator = pupilToFiles.iterator();
while (pupilToFileIterator.hasNext()) {
PupilToFile pupilToFile = pupilToFileIterator.next();
System.out.println("\n\n" + Cyan + pupilToFile + Restore);
}
verifyMoreParticipants(pupilToFiles, OIS, OOS, Counter);
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
public void verifyMoreParticipants(ArrayList<PupilToFile> pupilToFiles, ObjectInputStream OIS, ObjectOutputStream OOS, int Counter) {
Scanner input = new Scanner(System.in);
FileManagement fileManagement=new FileManagement();
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
String FeedBack, Request, Command;
try {
System.out.print("\n+--You are to confirm and verify if the given applicant(s) belong to this school.--+" +
"\n" + Cyan + "Enter command like: "+Yellow+"[yes 'username'/'no username']\n" + Restore + " ");
System.out.println(Green+Italic);
Command = input.nextLine();
System.out.println(Restore);
//checking if the chosen pupil exist
boolean Condition = checkingPupilObjectInArray(pupilToFiles, Command);
if (Condition) {
Iterator<PupilToFile> iterator = pupilToFiles.iterator();
while (iterator.hasNext()) {
PupilToFile pupilToFile = iterator.next();
if (pupilToFile.NoCommand.equals(Command) || pupilToFile.YesCommand.equals(Command)) {
if (Command.equalsIgnoreCase(pupilToFile.NoCommand)) {
System.out.println("\nYou have selected:\n" + Red + pupilToFile);
System.out.print("\nAre sure to reject this person?"+Yellow+"[yes/no]\n " + Restore);
System.out.print(Green);
Command = Input.nextLine();
System.out.print(Restore);
if (Command.equals("yes")) {
Request = "Reject";
OOS.writeObject(Request);
OOS.writeObject(pupilToFile);
iterator.remove();
//updating the file
fileManagement.AddRecordToFile("TextFile/MyFile1.text",pupilToFiles);
FeedBack = (String) OIS.readObject();
if (FeedBack.equalsIgnoreCase("Done")) {
controlApplicantsVerification(pupilToFiles, OIS, OOS, Counter);
break;
}
} else if (Command.equals("no")) {
controlApplicantsVerification(pupilToFiles, OIS, OOS, Counter);
break;
} else {
System.err.println("-----INVALID COMMAND!-----" +
"\n Type the command as it appears.( consider the spaces and the letter case).");
Thread.sleep(1000);
controlApplicantsVerification(pupilToFiles, OIS, OOS, Counter);
break;
}
}
//if it is a yes command
else {
System.out.println("\nYou have selected:\n" + Cyan + pupilToFile);
System.out.println("\nAre sure to Accept this person?"+Yellow+"[yes/no]" + Restore);
System.out.print(Green);
Command = Input.nextLine();
System.out.print(Restore);
if (Command.equals("yes")) {
Request = "Accept";
OOS.writeObject(Request);
OOS.writeObject(pupilToFile);
iterator.remove();
fileManagement.AddRecordToFile("TextFile/MyFile1.text",pupilToFiles);
FeedBack = (String) OIS.readObject();
if (FeedBack.equalsIgnoreCase("Done")) {
controlApplicantsVerification(pupilToFiles, OIS, OOS, Counter);
break;
}
} else if (Command.equals("no")) {
controlApplicantsVerification(pupilToFiles, OIS, OOS, Counter);
break;
} else {
System.err.println("-----INVALID COMMAND!-----" +
"\n Type the command as it appears.( consider the spaces and the letter case).");
controlApplicantsVerification(pupilToFiles, OIS, OOS, Counter);
break;
}
}
}
}
}//the error if the rep input a wrong Pupil number
else {
System.err.println("-----THE PERSON YOU ENTERED DOES NOT EXIST!-----" +
"\n Type the command as it appears.( consider the spaces and the letter case)." +
"\n For example:[ yes xxx]\n\n");
Thread.sleep(1000);
controlApplicantsVerification(pupilToFiles, OIS, OOS, Counter);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// this function will check if the selected pupil exist in the schools list
public boolean checkingPupilObjectInArray(ArrayList<PupilToFile> pupilToFiles, String Command) {
Iterator<PupilToFile> iterator = pupilToFiles.iterator();
while (iterator.hasNext()) {
PupilToFile pupilToFile = iterator.next();
if (pupilToFile.NoCommand.equals(Command) || pupilToFile.YesCommand.equals(Command)) {
return true;
}
}
return false;
}
//this is used to replay some actions in the verify participant function above
public void controlApplicantsVerification(ArrayList<PupilToFile> pupilToFiles, ObjectInputStream OIS, ObjectOutputStream OOS, int Counter) {
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
System.out.println(Green+"\n\nYou are left with:"+Restore);
Iterator<PupilToFile> pupilToFileIterator = pupilToFiles.iterator();
while (pupilToFileIterator.hasNext()) {
PupilToFile pupilToFile = pupilToFileIterator.next();
System.out.println("\n" + Cyan + pupilToFile + Restore);
}
String Command;
while(true){
if(pupilToFiles.isEmpty()){
System.err.println("-----No Applicants left-----");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
}
System.out.println("Verify More Participants?"+Yellow+"[yes/no]"+Restore);
System.out.print(Green+Italic);
Command = Input.nextLine();
System.out.print(Restore);
if (Command.equals("yes")) {
verifyMoreParticipants(pupilToFiles, OIS, OOS, Counter);
break;
} else if (Command.equals("no")) {
break;
}else{
System.err.println("-----INVALID COMMAND!-----" +
"\n Type the command as it appears.( consider the spaces and the letter case)." +
"\n For example:[ yes xxx]\n\n");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
controlApplicantsVerification(pupilToFiles, OIS, OOS, Counter);
break;
}
}
}
}
// THIS CLASS PUPIPL WILL CONTAIN ALL THE METHODS THAT IMPLEMENTS THE REQUIREMENTS OF A PUPIL , AND OF WHICH IT INHERITS OTHERS FROM THE USER
class Pupil extends User {
//displays challenges and enables a participant who is logged in to take up a given challenge
public void viewChallenge(Socket socket, ObjectInputStream OIS, ObjectOutputStream OOS, int Counter) {
ArrayList<Challenge> challenges = new ArrayList<>();
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
String FeedBack, Response;
try {
//sending a response to be server to initiate the sending of the challenge array
Response = "Generate Content";
OOS.writeObject(Response);
if (Counter == 1) {
System.err.print(" ONE MORE TRIAL REMAINING......\n\n");
Thread.sleep(1000);
}
// retrieving an array of challenge objects from the server
FeedBack = (String) OIS.readObject();
if (FeedBack.equalsIgnoreCase("No Challenges Yet!")) {
System.out.println(Red+"No challenges available!"+Restore);
} else {
System.out.println();
Response = "Send Data";
OOS.writeObject(Response);
challenges = (ArrayList<Challenge>) OIS.readObject();
int i=0;
String ChallengeNo="Challenge No",Challenge_Name="Challenge_Name",OpeningDate="Opening Date",ClosingDate="Closing Date",NumberOfQuestions="NumberOfQuestions",Status="Challenge Status",TimeAllowed="TimeAllowed";
System.out.println(Cyan +"+--------------+-----------------+----------------------+----------------------+-------------+-------------------+-------------------------+"+Restore);
System.out.printf("| %-10s | %-15s | %-20s | %-20s | %-10s | %-10s | %-20s |\n",ChallengeNo,Challenge_Name,OpeningDate,ClosingDate,TimeAllowed,NumberOfQuestions,Status);
System.out.println(Cyan +"+--------------+-----------------+----------------------+----------------------+-------------+-------------------+-------------------------+");
for(Challenge challenge:challenges){
//defining the challenge status whether the challenge is open/pending or closed
LocalDateTime localDateTime= LocalDateTime.now();
LocalDateTime ClosinglocalDateTime=challenge.ClosingDate;
LocalDateTime OpeningLocalDateTime=challenge.OpeningDate;
if (localDateTime.isAfter(ClosinglocalDateTime)) {
challenge.Status = "Challenge Closed";
} else if (localDateTime.isBefore(OpeningLocalDateTime)) {
challenge.Status = "Challenge Pending";
}else {
challenge.Status = "Challenge Open";
}
if (i>0) {
System.out.println("+--------------+-----------------+----------------------+----------------------+-------------+-------------------+-------------------------+");
}
System.out.println(challenge);
i++;
}
System.out.println("+--------------+-----------------+----------------------+----------------------+-------------+-------------------+-------------------------+");
System.out.println(Restore);
questionLoader(socket, OIS, OOS, Counter, challenges);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public void questionLoader(Socket socket, ObjectInputStream OIS, ObjectOutputStream OOS, int Counter, ArrayList<Challenge> challenges) {
AtomicInteger Timer =new AtomicInteger(0);//this is to track the remaining time while attempting questions
AtomicBoolean TerminateProcess=new AtomicBoolean(false);//this terminates the question loader and review process, but activates the logoutfuction
String ChallengeID=null;
if (Counter == 1) {
System.err.print(" ONE MORE TRIAL REMAINING!......\n");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//creating a question arraylist object to hold questions loaded from the server
ArrayList<Question> questions = new ArrayList<>();
String Answer,NumberOfQuestions=null;
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
String FeedBack, Request,Command;
System.out.print("\n\n+-----Do you want to Attempt a challenge/Another challenge"+Yellow+"[yes/no]?"+Restore+"-------+\n ");
System.out.print(Green+Italic);
Command = Input.nextLine();
System.out.print(Restore);
try {
switch (Command) {
case "yes":
System.out.print("\n+-----Enter " + Yellow + "[attempt challenge 'challenge number']----+\n " + Restore);
System.out.print(Green + Italic);
Command = Input.nextLine();
System.out.print(Restore);
//checking if the chosen challenge exist
boolean Condition = checkingChallengeObjectInArray(challenges, Command);
String NumberOfQuestion=null;
if (Condition) {
Iterator<Challenge> iterator = challenges.iterator();
while (iterator.hasNext()) {
Challenge challenge = iterator.next();
if (challenge.AttemptCommand.equalsIgnoreCase(Command)) {
if (challenge.Status.equalsIgnoreCase("Challenge Closed")){
System.err.println("-----This Challenge Was Closed!-----\n Select another challenge which is open. ");
Thread.sleep(1000);//simulate processing for one second
//calling the function question loader
Counter = 0;
questionLoader(socket, OIS, OOS, Counter, challenges);
break;
}
else if(challenge.Status.equalsIgnoreCase("Challenge Pending")){
System.err.println("-----This Challenge is not yet open!-----\n Select another challenge which is open. ");
Thread.sleep(1000);//simulate processing for one second
//calling the function question loader
Counter = 0;
questionLoader(socket, OIS, OOS, Counter, challenges);
break;
}
else{
//checking whether this challenge was once done by the pupil
OOS.writeObject(challenge);
FeedBack=(String)OIS.readObject();
if(FeedBack.equalsIgnoreCase("already done")){
System.err.println("-----You already attempted this challenge!-----\n Select another challenge which you have never attempted. ");
Thread.sleep(1000);//simulate processing for one second
//calling the function question loader
Counter = 0;
questionLoader(socket, OIS, OOS, Counter, challenges);
break;
}else {
//capturing the ID for a selected challenge as to initialize the ChID of the submission later on
ChallengeID = challenge.ID;
Timer.set(Integer.parseInt(challenge.TimeAllowed));
//intialising the number of questions to be loaded according to the challenge
NumberOfQuestion = challenge.NumberOfQuestions;
String ChallengeNo = "Challenge No", Challenge_Name = "Challenge_Name", OpeningDate = "Opening Date", ClosingDate = "Closing Date", TimeAllowed = "TimeAllowed", Status = "Challenge Status";
NumberOfQuestions = "NumberOfQuestions";
System.out.println("\n\n+-----You have Chosen to Attempt challenge:-----------+");
System.out.println(Cyan + "+--------------+-----------------+----------------------+----------------------+-------------+-------------------+-------------------------+" + Restore);
System.out.printf("| %-10s | %-15s | %-20s | %-20s | %-10s | %-10s | %-20s|\n", ChallengeNo, Challenge_Name, OpeningDate, ClosingDate, TimeAllowed, NumberOfQuestions, Status);
System.out.println(Cyan + "+--------------+-----------------+----------------------+----------------------+-------------+-------------------+-------------------------+");
System.out.println(challenge);
System.out.println(Cyan + "+--------------+-----------------+----------------------+----------------------+-------------+-------------------+-------------------------+");
System.out.println(Restore);
}
}
}
}
System.out.print("+-----Are you sure to Start the Challenge?" + Yellow + "[yes/no]----+\n" + Restore + " ");
System.out.print(Green + Italic);
Command = Input.nextLine();
System.out.print(Restore);
//checks whether reply is "Yes" or " no"
if (Command.equals("yes")) {
System.out.println();
Request = "Loadquestions "+NumberOfQuestion;
OOS.writeObject(Request);
//receiving and evaluating feedback from the server
FeedBack = (String) OIS.readObject();
if (FeedBack.equalsIgnoreCase("No results Found")) {
System.err.println("Questions Are not yet Uploaded! Try again Later.");
Thread.sleep(1000);//simulate processing for one second
Counter = 0;
logoutHandler(socket, OIS, OOS, Counter, challenges);
break;
} else {
System.out.println(Cyan + "+-----INSTRUCTIONS:-----+\n 1). Correct Answer Score:3mks\n 2). Wrong Answer score:-3mks\n 3).+-----If you are unsure about the question, enter a minus(-):-0mks\n\n If you are Ready, Press " + Yellow + "(enter key)" + Restore + Cyan + " to continue with the challenge-----+ " + Restore);
//Creating a pause for the Participant to read through the instructions and proceeds when he precess Enter
String ParticipantReadInstructions = Input.nextLine();
//if questions are present, thy are loaded in questions arraylist
questions = (ArrayList<Question>) OIS.readObject();
int TimeLimit = Timer.get();// to time for the entire challenge attempt(this is seconds)
int Questions = Integer.valueOf(NumberOfQuestion);//used in numbering of questions
//This thread simulate count down using the for loop and updating the atomic integer by 1, after every second
new Thread(new Runnable() {
int CurrentTime;
int ModifiedTime;
@Override
public void run() {
for (int i = TimeLimit; i > 0; i--) {
CurrentTime = Timer.get();
ModifiedTime = CurrentTime - 1;
Timer.set(ModifiedTime);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(Red + "\n\nTimeOut!\n" + Cyan + "Your attempts have been automatically submitted.\n\n+-----Press "+Yellow+"( Enter key )"+Restore+ Cyan+" to continue-----+" + Restore);
}
}).start();
//initial CLI user interface management class
class UserInterface{
Socket socket;
ObjectInputStream OIS;
ObjectOutputStream OOS;
Scanner Input= new Scanner(System.in);
Pupil pupil=new Pupil();
User user=new User();
SchoolRep Rep=new SchoolRep();
String Command,FirstOption, SecondOption;
//displays and manages initial screen prompts
public void processCommand(int Counter){
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
if(Counter==1){
System.err.print(" ONE MORE TRIAL REMAINING!......\n\n");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("+------------------------------+");
System.out.println("+ SELECT ANY OPTION AND PROCEED+");
System.out.println("+------------------------------+");
System.out.println(" register\n login\n view challenge");
System.out.print("\nSelected Option: ");
System.out.print(Green+Italic);
Command=Input.nextLine();
System.out.print(Restore);
//initialising the first option variable
if (Command.equals("register")) {
FirstOption = "Register";
} else if (Command.equals("login")) {
FirstOption = "Login";
} else if (Command.equals("view challenge")) {
FirstOption = "ViewChallenge";
}
// calling the function to handle the second selection accordingly
switch (Command) {
case "register":
secondCommandManagement(FirstOption,Counter);
break;
case "login":
//function call
secondCommandManagement(FirstOption,Counter);
break;
case "view challenge":
System.out.println(Cyan+" You have chosen "+FirstOption+"!");
System.out.println(Restore);
user.viewChallenge();
break;
default://capture the invalid user inputs up to max of TWO TIMES.
System.err.println("-----INVALID OPTION!-----" +
"\n You must only Use small letters throughout. And also, insert each command as it appears" +
"\n Thank you!");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Counter++;
if (Counter == 2) {
System.err.println(" Exceeded maximum trials!!\n Try again Later, thank you. ");
break;
}
processCommand(Counter);
}
}
// displays and manages second Option prompts
public void secondCommandManagement(String FirstOption,int Counter) {
//Declaring Formatting variables
String Cyan = "\u001B[36m";
String Green = "\u001B[32m";
String Restore = "\u001b[0m";
String Red = "\u001B[31m";
String Italic = "\033[3m";
String Yellow="\u001B[33m";
Counter=0;
System.out.println(Cyan+" You have chosen "+FirstOption+"!"+Restore) ;
System.out.println("\n+-------------------------+|");
System.out.println("+ "+FirstOption+" as:");
System.out.println("+-------------------------+|");
System.out.print(" school representative \n pupil\n back\n\nSelect Option: ") ;
System.out.print(Green+Italic);
Command= Input.nextLine();
System.out.print(Restore);
//Initialising the second option variable
if(Command.equals("school representative")){
SecondOption="School Representative";
System.out.println(Cyan+" You have chosen, "+FirstOption+" as "+SecondOption+"."+Restore) ;
}
else if(Command.equals("pupil")){
SecondOption="Pupil";
System.out.println(Cyan+" You have chosen, "+FirstOption+" as "+SecondOption+"."+Restore) ;
}
else if(Command.equals("back")){
SecondOption="Back";
System.out.println(Cyan+" You have chosen, "+SecondOption+"."+Restore) ;
}
// evaluating the first options
//if it is register execute this code block
if(FirstOption=="Register") {
switch (Command) {
case "school representative":
//calling register method of schoolRepresentative class
Rep.register(SecondOption,Counter,FirstOption);
break;
case "pupil":
//calling register method of pupil class
pupil.register(SecondOption,Counter,FirstOption);
break;
case "back":
back(Counter);
break;
default://error if invalid option
System.err.println("-----INVALID OPTION!-----" +
"\n You must only Use small letters throughout. And also, insert each command as it appears");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Counter++;
if (Counter == 2) {
System.err.println(" Exceeded maximum trials!!\n Try again Later, thank you. ");
break;
}
processCommand(Counter);
}
}
//if it is a login
else if(FirstOption=="Login"){
switch (Command) {
case "school representative"://calling Login method of schoolRepresentative class
Counter=0;
Rep.login(SecondOption,Counter,FirstOption);
break;
case "pupil":
Counter=0;
pupil.login(SecondOption,Counter,FirstOption);//calling login method of schoolRepresentative class
break;
case "back":
back(Counter);
break;
default://error if invalid option
System.err.println("-----INVALID OPTION!-----" +
"\n You must only Use small letters throughout. And also, insert each command as it appears" +
"\n Thank you!");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Counter++;
if (Counter == 2) {
System.err.println(" Exceeded maximum trials!!\n Try again Later, thank you. ");
break;
}
processCommand(Counter);
}
}
}