-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.java
More file actions
2738 lines (2379 loc) · 174 KB
/
GUI.java
File metadata and controls
2738 lines (2379 loc) · 174 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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.sql.*; // import the big package.
import java.time.LocalDate;
public class GUI {
public static String userID = ""; // set the basic String.
public static boolean isAdmin = false; // set the boolean as false.
public static void main(String[] args) throws Exception {
while (true) {
//Scanner ChoiceIntroPage = new Scanner(System.in);
System.out.println("------------------------");
System.out.println("WELCOME TO OUR DATABASE APP");
System.out.println("");
System.out.println("--------- OPTIONS ---------");
System.out.println("CHOOSE 1 FOR LOGIN");
System.out.println("CHOOSE 2 FOR REGISTER");
System.out.println("CHOOSE 3 TO QUIT");
System.out.print("ENTER CHOICE: ");
Scanner ChoiceIntroPage = new Scanner(System.in); // read in the input; either 1, 2, or 3.
String ChoiceIntroString = ChoiceIntroPage.nextLine(); // we assume that it is an int.
if (checkIfNumeric(ChoiceIntroString) && Integer.parseInt(ChoiceIntroString) == 1) { // assume login.
int resultofLogin = checkLogin(); // do login, and eventually go from there. This int is unnecessary unless
// you decide to exit out of the login screen.
if (resultofLogin == -1) { // if -1, we'll choose to break. Zeroes and other things continue the outer loop.
break; // this ends the app.
}
} else if (checkIfNumeric(ChoiceIntroString) && Integer.parseInt(ChoiceIntroString) == 2) { // assume register.
int resultofRegister = register(); // do login, and eventually go from there. This int is unnecessary unless
// you decide to exit out of the login screen.
if (resultofRegister == -1) { // if -1, we'll choose to break.
break;
}
// goto register.
} else if (checkIfNumeric(ChoiceIntroString) && Integer.parseInt(ChoiceIntroString) == 3) { // assume exit solely chosen in the choice intro page
System.out.println("Thank you for using our app.");
ChoiceIntroPage.close(); // close the scanner.
System.exit(1); // end immediately here.
} else { // assume incorrect input.
System.out.println("You entered an incorrect number. Try again. Or quit.");
System.out.println("");
}
}
System.out.println("Thank you for using our app."); // exit screen obtained from exiting from other places.
System.exit(1); // to make sure this works.
}
public static Connection getConnection() throws Exception { // open a Connection to the database.
Connection conn = null;
// Properties connectionProps = new Properties();
// connectionProps.put("user", this.userName);
// connectionProps.put("password", this.password);
Class.forName("org.mariadb.jdbc.Driver"); // test if the driver that allows this connection exists.
System.out.println("Driver loaded"); // nice little printout message.
conn = DriverManager.getConnection(
"jdbc:" + "mysql" + "://" +
"localhost" + "/TMB", "test", "testpwd"); // connect using a link.
System.out.println("Connected to database"); // print out nice message.
return conn; // return the connection back to checkLogin.
}
public static int checkLogin() throws Exception {
Connection newConnect = getConnection(); // check getConnection;
Scanner userpwd = new Scanner(System.in); // login username/pwd scanner.
while (true) { // this keeps repeating if your username is wrong/doesn't exist in the database.
System.out.println("----------- LOGIN SCREEN -------------");
System.out.print("ENTER YOUR USERNAME: ");
String username = userpwd.nextLine(); // get the username. // test "chal68";
if (username.equalsIgnoreCase("exit")) {
System.out.println("You exited the checkLogin at User, going back to the main welcome screen. Good-bye.");
return 0; // go to the main welcome screen.
} else if (username.equalsIgnoreCase("exitfull")) {
System.out.println("You exited the checkLogin at User, basically ending your usage of the app. Good-bye.");
return -1; // quit the app.
} else {
//System.out.println(""); // need to go down.
Statement usercheck = newConnect.createStatement(); // we create a statement to be used.
String userQuery = "SELECT ID FROM User WHERE ID = '" + username + "'"; // create the query and then execute. QUERY TO CHECK USERNAME VALIDITY
ResultSet userSet = usercheck.executeQuery(userQuery); // see? Get the results as a ResultSet.
if (!(userSet.isBeforeFirst())) { // i'm not gonna explain this one... but... if the set has no rows, then the set is empty.
System.out.println("you failed. Username is incorrect. Try again."); // if the set is empty... then the username is wrong.
System.out.println("------- RETURNING TO LOGIN SCREEN, USERNAME DOESN'T EXIST --------");
} else {
while (true) { // an inner while-true loop, that only executes repeatedly if you fail your password login.
System.out.print("ENTER YOUR PASSWORD: "); // enter the password. test "eightchar".
String password = userpwd.nextLine();
if (password.equalsIgnoreCase("exit")) {
System.out.println("You exited the checkLogin at Password to go to the main welcome screen. Good-bye.");
return 0; // goes to the main welcome screen
} else if (password.equalsIgnoreCase("exitfull")) {
System.out.println("You exited the checkLogin at password to quit the app. Good-bye.");
return -1; // quits the app
} else {
System.out.println("");
Statement pwdcheck = newConnect.createStatement();
String passQuery = "SELECT password FROM User WHERE ID = '" + username + "' AND password = '" + password + "'"; // QUERY TO CHECK USERNAME + PWD VALIDITY
ResultSet pwdSet = pwdcheck.executeQuery(passQuery);
if (!(pwdSet.isBeforeFirst())) {
System.out.println("you entered password wrong. try again.");
System.out.println("-------- RETURNING TO LOGIN SCREEN, PASSWORD DOESN'T MATCH WITH GIVEN USERNAME ---------");
} else {
System.out.println("Checking admin now...");
userID = username; // set the static variable as username.
Statement adminCheck = newConnect.createStatement(); // create new statement for admin check.
String adminQuery = "SELECT ID From Admin WHERE ID = '" + userID + "'"; // admin query creation
ResultSet adminSet = adminCheck.executeQuery(adminQuery); //
if (!(adminSet.isBeforeFirst())) {
System.out.println("Congrats, you're now logged in.");
while(true) {
int passengerGUIresult = MainPassengerGUI(); // check how this works
if (passengerGUIresult == 1) {
int leaveReview = leaveReview(userID, newConnect); // LEAVE REVIEW
System.out.println(); // shouldn't do anything really.
} else if (passengerGUIresult == 2) { // VIEW REVIEWS
int viewResults = viewReviews(userID, newConnect, "REGULAR");
System.out.println();
} else if (passengerGUIresult == 3) {
int cardSuccess = buyCard(userID); // BUYING CARD
System.out.println();
} else if (passengerGUIresult == 4) { // GO ON TRIP
int tripCreatesuccess = goOnTrip(userID);
System.out.println();
} else if (passengerGUIresult == 5) { // VIEW TRIP
int viewTripSuccess = viewTrip(userID, "card_type");
System.out.println();
} else if (passengerGUIresult == 6) { // EDITING USER PROFILE
int editSuccess = editUser(userID);
if (editSuccess == -1) {
return 0; // get back to the welcoming screen.
}
System.out.println();
} else if (passengerGUIresult == 7) { // GOTO LOGIN SCREEN
break; // this should break out of the inner loop about the password filling in and go straight to the login screen.
} else if (passengerGUIresult == 8) { // GOTO WELCOME SCREEN
return 0; // this takes us to the welcome screen.
} else if (passengerGUIresult == 9) { // QUIT FULLY
return -1; // this quits the app and gives us the quit screen.
} else {
System.out.println("This should never be reached at all. This is in the passengerGui check in checkLogin.");
System.out.println("Crash app completely.");
System.exit(1); // this breaks the app with no quit screen other than "crash app completely."
}
}
break;
} else {
System.out.println("LOGGED IN AS ADMIN..."); // TIME TO DO THIS AS ADMIN FUCK YES
isAdmin = true; // set the admin.
while(true) {
int adminGUIresult = MainAdminGUI(); // check how this works
if (adminGUIresult == 1) { // VIEW TRIPS
int viewTripSuccess = viewTrip(userID, "card_type");
System.out.println();
} else if (adminGUIresult == 2) { // BUY CARD
int cardSuccess = buyCard(userID);
System.out.println();
} else if (adminGUIresult == 3) { // GO ON TRIP
int tripCreateSuccess = goOnTrip(userID);
System.out.println();
} else if (adminGUIresult == 4) { // REVIEW PASSENGER REVIEWS
int viewReviews = reviewPassengerReviewsADMIN(newConnect);
System.out.println();
} else if (adminGUIresult == 5) { // EDIT PROFILE
int editSuccess = editAdmin(userID);
System.out.println();
} else if (adminGUIresult == 6) { // ADD STATION
int stationAddSuccess = addStation();
System.out.println();
} else if (adminGUIresult == 7) { // GOTO LOGIN SCREEN
int lineAddSuccess = addLine();
System.out.println();
break; // this should break out of the inner loop about the password filling in and go straight to the login screen.
} else if (adminGUIresult == 8) {
break;// GOTO LOGIN
} else if (adminGUIresult == 9) { // QUIT TO WELCOME
return 0;
} else if (adminGUIresult == 10) { // QUIT FULLY.
return -1;
} else {
System.out.println("This should never be reached at all. This is in the passengerGui check in checkLogin.");
System.out.println("Crash app completely.");
System.exit(1); // this breaks the app with no quit screen other than "crash app completely."
}
}
break; // this is necessary to go back to the login screen. using only one break, as in the conditional for adminGui == 8, will go back to enter password.
}
}
}
}
}
}
}
}
public static int register() throws Exception {
Connection newConnect = getConnection();
Scanner registration = new Scanner(System.in);
String firstName;
String mi;
String lastName;
String email;
String userID;
String pass1;
String pass2;
while(true) {
System.out.print("ENTER FIRST NAME: ");
firstName = registration.nextLine();
if (firstName.equalsIgnoreCase("exit")) {
System.out.println("You exited the registration at FirstName. Good-bye.");
return 0; // this goes to the two lines all the way at the end of the method, the 'unreachables.'
} else {
if (firstName.length() == 0 || firstName.equals("NULL")) {
System.out.println("Type a first name please");
} else {
while (true) {
System.out.println("ENTER MIDDLE INITIAL: ");
String middleI = registration.nextLine();
mi = middleI.length() == 0 ? "NULL" : middleI;
if (mi.equalsIgnoreCase("exit")) {
System.out.println("You exited the registration at Middle Initial. Good-bye.");
return 0; // this goes to the two lines all the way at the end of the method, the 'unreachables.'
} else {
if (mi.length() > 1 && !mi.equals("NULL")) {
System.out.println("Middle initial should be one character.");
} else {
while (true) {
System.out.println("ENTER LAST NAME: ");
lastName = registration.nextLine();
if (lastName.equalsIgnoreCase("exit")) {
System.out.println("You exited the registration at LastName. Good-bye.");
return 0;
} else {
if (lastName.length() == 0 || lastName.equals("NULL")) {
System.out.println("Type a last name please");
} else {
while (true) {
System.out.println("ENTER EMAIL: ");
email = registration.nextLine();
if (email.equalsIgnoreCase("exit")) {
System.out.println("You exited the registration at Email. Good-bye.");
return 0;
} else {
if (email.length() == 0 || email.equals("NULL")) {
System.out.println("Type an email please");
} else {
while (true) {
System.out.println("ENTER USERID: ");
userID = registration.nextLine();
if (userID.equalsIgnoreCase("exit")) {
System.out.println("You exited the registration at UserID. Good-bye.");
return 0;
} else {
Statement rgstrcheck = newConnect.createStatement();
String testQuery = "SELECT * FROM User WHERE ID='" + userID + "'";
ResultSet testSet = rgstrcheck.executeQuery(testQuery);
boolean unique = true;
if (userID.length() == 0 || userID.equals("NULL")) {
System.out.println("Type a UserID please");
} else if (testSet.isBeforeFirst()) {
System.out.println("Choose a unique UserID pls");
} else {
while (true) {
System.out.println("ENTER PASSWORD: ");
pass1 = registration.nextLine();
if (pass1.equalsIgnoreCase("exit")) {
System.out.println("You exited the registration at Password. Good-bye.");
return 0;
} else {
if (pass1.length() < 8) {
System.out.println("Type a password of length 8 or greater please");
} else {
while (true) {
System.out.println("RE-ENTER PASSWORD: ");
pass2 = registration.nextLine();
if (pass2.equalsIgnoreCase("exit")) {
System.out.println("You exited the registration at Password. Good-bye.");
return 0;
} else {
if (!pass1.equals(pass2)) {
System.out.println("Make sure the passwords match");
} else {
System.out.println("");
mi = mi.equals("NULL") ? mi : "'" + mi + "'";
String passQuery = "INSERT INTO User VALUES ('" + userID + "', '" + firstName + "', " + mi + ", '" + lastName + "', '" + pass1 + "', '" + email + "')";
ResultSet rgstrSet = rgstrcheck.executeQuery(passQuery);
// String testQuery = "SELECT * FROM User WHERE ID='" + userID + "'";
// ResultSet testSet = rgstrcheck.executeQuery(testQuery);
// if (!(testSet.isBeforeFirst())) {
// System.out.println("username is not unique. try again.");
// System.out.println("-------- RETURNING TO LOGIN SCREEN, PASSWORD DOESN'T MATCH WITH GIVEN USERNAME ---------");
// } else {
System.out.println("Congrats, you're now registered.");
return 0; // break completely;
// }
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
public static int MainPassengerGUI() throws Exception { // after login on the user is done.
Connection newConnect = getConnection();
Scanner choosePassengerGUI = new Scanner(System.in);
String nameUser = "SELECT first_name, minit, last_name FROM User WHERE ID='" + userID + "'";
Statement nameUserStat = newConnect.createStatement();
ResultSet getNameUser = nameUserStat.executeQuery(nameUser);
getNameUser.next();
String firstname = getNameUser.getString("first_name");
String midinit = getNameUser.getString("minit");
String lastname = getNameUser.getString("last_name");
while(true) {
System.out.println("------------ MAIN PAGE ---------------------");
System.out.println();
System.out.println("Welcome " + firstname + " " + midinit + " " + lastname);
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user.
System.out.printf("CHOOSE A NUMBER TO EXPLORE DIFFERENT OPTIONS. %n 1. Leave Review %n 2. View Reviews %n 3. Buy Card %n 4. Go On Trip %n 5. View Trips %n"
+ " 6. Edit Profile %n 7. Goto Login %n 8. Goto Welcome Screen %n 9. Quit Fully %n");
System.out.print("CHOOSE AN OPTION: ");
int choosePassengerInt = choosePassengerGUI.nextInt(); // same old, basically.
if (choosePassengerInt == 1) {
// leaveReview(newConnect);
// break; //return 0; // leave review
System.out.println("------------LEAVE REVIEW------------"); // LEAVE REVIEW
System.out.println("");
return 1;
} else if (choosePassengerInt == 2) {
System.out.println("------------VIEW REVIEWS------------");// view review
System.out.println("");
return 2;
} else if (choosePassengerInt == 3) {
System.out.println("------------PURCHASE CARD------------");
System.out.println("");
return 3; //return 3(Go to card purchase screen);
} else if (choosePassengerInt == 4) { // Create Trip
System.out.println("------------PLAN TRIP------------");
System.out.println("");
return 4; //return 4(Go to Go On Trip screen)
} else if (choosePassengerInt == 5) { // View Trip
System.out.println("--------------VIEWING TRIPS----------");
return 5;
} else if (choosePassengerInt == 6) { // edit profile
System.out.println("------------EDIT USER INFORMATION------------");
System.out.println("");
return 6; //return 0;
} else if (choosePassengerInt == 7) { // goto login screen. this means logout.
System.out.println("------------LOGGING OUT GOTO LOGIN SCREEN------------");
System.out.println("");
userID = ""; // reset as empty.
isAdmin = false; // reset as false even though it is false.
return 7;
} else if (choosePassengerInt == 8) { // goto welcome screen // means we must logout.
System.out.println("------------LOGGING OUT GOTO WELCOME SCREEN------------");
System.out.println("");
userID = "";
isAdmin = false;
return 8;
} else if (choosePassengerInt == 9) { // quit fully. full logout as well.
System.out.println("------------LOGGING OUT EXIT FULLY------------");
System.out.println("");
userID = "";
isAdmin = false;
return 9;
} else {
System.out.println("You chose an incorrect number. Try again.");
}
}
// breaks out of the big while-loop, will hit if exit at password.
}
public static int leaveReview(String userID, Connection connection) throws Exception { // leave reviews, USER/ADMIN
Connection newConnection = connection; // pass the connection in.
// be able to list all the stations
Statement getAllStations = newConnection.createStatement();
Scanner chooseStation = new Scanner(System.in); // you're gonna use this to get the station to work with.
int shoppingRating = -1; // initialization of ratings stuff.
int connectionRating = -1;
String nameOfStation = null;
String commentLeft = null;
// We want the stations that are admin-approved AND are on admin-approved lines.
String getStationsQuery = "SELECT name FROM Station ORDER BY name"; // order by name, assume we only have to get from stations.
String getStationQueryNum = "SELECT COUNT(name) FROM Station"; // get the count of names.nnn
// String getStationsQuery = "SELECT name FROM Station JOIN Station_On_Line WHERE Station_On_Line.station_name = Station.name ORDER BY"; // this gets us the actual table of names.
// String getStationQueryNum = "SELECT COUNT(name) FROM Station JOIN Station_On_Line WHERE Station_On_Line.station_name = Station.name"; // this gets us the count.
ResultSet getStations = getAllStations.executeQuery(getStationsQuery); // get the stations.
ResultSet getNumStations = getAllStations.executeQuery(getStationQueryNum); // get the count of stations.
int getNum = -5; // set random num
while(getNumStations.next()) {
getNum = Integer.parseInt(getNumStations.getString("COUNT(name)")); // getNum = count of stations.
}
String[] arrStations = new String[getNum]; // create string array to hold the names of the stations
int fillIndex = 0; // simple loop to go through ResultSet getStations.
while (getStations.next()) {
arrStations[fillIndex] = getStations.getString("name"); // get the value out of the column "name"
fillIndex++;
}
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user.
String actualArray = Arrays.toString(arrStations); // turn this into a printable thing. finally, fucking use ARRAYS.
while(true) { // a massive loop because fuck
System.out.println("ARRAY FOR STATIONS: " + Arrays.toString(arrStations)); // print array.
System.out.print("CHOOSE BY INDEX YOUR STATION; 0 BEING FIRST, N - 1 BEING THE NTH: "); // choose by INDEX from the array.
String getInt = chooseStation.nextLine();
if (!checkIfNumeric(getInt) || Integer.parseInt(getInt) < 0 || Integer.parseInt(getInt) >= getNum) {
System.out.println("Pick a number greater than 0 and less than or equal to n-1."); // check invalid INDEX
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user.
} else {
shoppingRating = -1; // assume we did get valid index, set shopping and connection ratings.
connectionRating = -1;
while(true) { // these smaller and smaller infinite loops restrict our errors, so making one error forces us to solve that
// one error before moving on, input-wise.
System.out.print("CHOOSE A SHOPPING RATING FROM 0 TO 5: ");
String shopRating = chooseStation.nextLine();
shoppingRating = checkIfNumeric(shopRating) ? Integer.parseInt(shopRating) : -1;
if (shoppingRating < 0 || shoppingRating > 5) {
System.out.println("Choose a valid rating."); // valid check on shopping rating.
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user.
} else {
while(true) {
System.out.print("CHOOSE A CONNECTION RATING FROM 0 TO 5: "); // valid check on
String connRating = chooseStation.nextLine();
connectionRating = checkIfNumeric(connRating) ? Integer.parseInt(connRating) : -1;
if (connectionRating < 0 || connectionRating > 5) {
System.out.println("Choose a valid number");
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user.
} else {
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user. // throwing identification everywhere so jackson doesn't get mad.
Scanner captureReview = new Scanner(System.in);
System.out.print("LEAVE A COMMENT ABOUT THE STATION (OPTIONAL): ");
commentLeft = captureReview.nextLine();
if (commentLeft.length() == 0 || commentLeft.equals("NULL")) {
commentLeft = "NULL";
}
ResultSet r = getAllStations.executeQuery("SELECT COUNT(rid) AS rowcount FROM Review WHERE passenger_ID='" + userID + "'");
r.next();
int count = r.getInt("rowcount") + 1;
r.close();
String passQuery = "INSERT INTO Review VALUES ('" + userID + "', " + count + ", " + shoppingRating + ", " + connectionRating +", '" + commentLeft + "', NULL, 'pending', NULL, '" + arrStations[Integer.parseInt(getInt)] + "')";
ResultSet rgstrSet = getAllStations.executeQuery(passQuery);
System.out.println("You left a review.");
return 0;
// TODO: OBTAIN THE NEW RID BY GETTING ALL REVIEWS BY A PARTICULAR USER AND GETTING THE MAX
// NUMBER OF THOSE RIDS, ADD 1 TO GET THE NEW RID - IT'S A NEW REVIEW.
// TODO: WRITE THE QUERY TO ADD EVERYTHING AS A REVIEW TUPLE.
// TODO: TEST AND SEE IF THIS WORKS
// edit timestamp should be null
}
}
}
}
}
}
//System.exit(1); // exit for now.
}
public static int viewReviews(String userID, Connection newConnect, String endingString) throws Exception {
Connection gatherData = newConnect; // get the connection;
String idToUse = userID; // get the id, even though it's static you shouldn't need it.
int numOfQueries = -1;
String[][] displayArr;
String[] actualArrChoice = new String[]{"rid", "station_name", "shopping", "connection_speed", "approval_status"};
String gatherQuery;
String nameUser = "SELECT first_name, minit, last_name FROM User WHERE ID='" + userID + "'";
Statement nameUserStat = newConnect.createStatement();
ResultSet getNameUser = nameUserStat.executeQuery(nameUser);
getNameUser.next();
String firstname = getNameUser.getString("first_name");
String midinit = getNameUser.getString("minit");
String lastname = getNameUser.getString("last_name");
ArrayList<String> arrChoice = new ArrayList<>(Arrays.asList(actualArrChoice)); // we gotta check this.
Scanner getReviewData = new Scanner(System.in);
while(true) {
System.out.println("Welcome " + firstname + " " + midinit + " " + lastname);
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user.
System.out.println();
System.out.println("-----------------REVIEWS TO VIEW-----------------");
if (!endingString.equals("REGULAR")) {
gatherQuery = "SELECT rid, station_name, shopping, connection_speed, comment, approval_status FROM Review WHERE passenger_ID='" + idToUse + "'" + " ORDER BY " + endingString;
System.out.println("GATHER QUERY: " + gatherQuery);
} else {
gatherQuery = "SELECT rid, station_name, shopping, connection_speed, comment, approval_status FROM Review WHERE passenger_ID='" + idToUse + "'";
System.out.println("GATHER QUERY: " + gatherQuery);
}
Statement gatherAllReviews = newConnect.createStatement();
String gatherNumQuery = "SELECT COUNT(rid) FROM Review WHERE passenger_id='" + idToUse + "'";
ResultSet reviewInfo = gatherAllReviews.executeQuery(gatherQuery); // this gets us all the info of the reviews.
ResultSet reviewNum = gatherAllReviews.executeQuery(gatherNumQuery); // this gets us the numerical stuff.
// SELECT rid, station_name, shopping, connection_speed, comment, approval_status FROM Station WHERE userID = passenger_ID;
System.out.println("CHECKING WHETHER EMPTY ARRAY OR ACTUAL ARRAY EXISTS.");
if (!(reviewNum.isBeforeFirst())) {
System.out.println("THERE ARE NO REVIEWS PUBLISHED. RETURN TO THE MAIN GUI.");
return 0;
} else {
System.out.println("THE ARRAY OF REVIEWS: ");
System.out.println();
while (reviewNum.next()) {
numOfQueries = Integer.parseInt(reviewNum.getString("COUNT(rid)"));
System.out.println("NUMBER OF REVIEWS: " + numOfQueries);
}
displayArr = new String[numOfQueries + 1][6];
displayArr[0][0] = "RID"; // fill in the top part of the multi dim array with the categories.
displayArr[0][1] = "STATION";
displayArr[0][2] = " SHOPPING_NUM";
displayArr[0][3] = " CONN_SPEED";
displayArr[0][4] = " COMMENT_TEXT";
displayArr[0][5] = " APPROVAL_STATUS";
int rowInt = 1;
int colInt = 1;
System.out.println("ARRAY BEING FILLED IN.");
while (reviewInfo.next()) {
if (rowInt > numOfQueries) {break;}
while(colInt <= 6) {
displayArr[rowInt][colInt - 1] = colInt == 1 ? reviewInfo.getString(colInt) : " " + reviewInfo.getString(colInt);
colInt++;
}
rowInt++;
colInt = 1;
}
System.out.println(Arrays.deepToString(displayArr).replace("], ", "]\n\n"));
// be able to choose various things, such as the review and the station. Focus on this now.
System.out.println();
System.out.println("----------IMPORTANT INFORMATION TO READ--------------");
System.out.println("THERE ARE TWO THINGS YOU CAN DO - EITHER CHOOSE A REVIEW"
+ " TO EDIT OR STATION TO LEARN MORE ABOUT, OR SORT/ORDER ALL COLUMNS EXCEPT FOR COMMENT.");
System.out.println();
//rid, station_name, shopping, connection_speed, comment, approval_status
System.out.println("If you want to choose a station or review, type in the indices of the array, where 10 refers to the first review with RID 1. 150 would be a review with RID 15.");
System.out.println();
System.out.println();
System.out.println("Or, if you want to sort columns, here are your column choices: rid, station_name, shopping, connection_speed, approval_status");
System.out.println();
System.out.println();
System.out.println("To sort a column in regular order, type in: SORT rid ASC, or SORT connection_speed ASC");
System.out.println();
System.out.println();
System.out.println("Use SORT rid DESC to order rids in reverse, descending order.");
System.out.println();
System.out.println();
System.out.println("If you'd like to quit the page and be taken to the main GUI, type in EXIT.");
System.out.println();
System.out.println();
System.out.print("ENTER YOUR CHOICE NOW: ");
String whatChoice = getReviewData.nextLine(); // get the result of what they want.
if (whatChoice.length() < 2) {
System.out.println("INCORRECT ENTRY. TRY AGAIN.");
} else if (whatChoice.equalsIgnoreCase("exit")) {
return 0;
} else if (checkIfNumeric(whatChoice)) {
int checkInt = Integer.parseInt(whatChoice); // if this is a number, we have to do some checks.
if (checkInt > (numOfQueries * 10 + 1) || (checkInt < 9) || (checkInt % 10 > 1)) { // some insane fuckery is happening here.
System.out.println("These are unacceptable numerical choices. Pick again.");
} else {
int secondArrIndex = checkInt % 10;
int firstArrIndex = checkInt / 10;
System.out.println("This is the result of the index picked: " + displayArr[firstArrIndex][secondArrIndex]);
if (secondArrIndex == 1) {
stationDisplay(displayArr[firstArrIndex][secondArrIndex], gatherData); // the station and line displays.
} else {
int editingSuccess = editReview(displayArr[firstArrIndex][secondArrIndex]);
System.out.println("EDITED REVIEW");
}
//System.out.println("EXITING.");
//System.exit(1); // if done correctly, this will allow us to pick either a review to edit or a station to look at.
}
} else {
String[] breakArr = whatChoice.split(" "); // assume we have a non-numeric string. We have to figure out how to actually order by.
if (breakArr.length != 3) {
System.out.println("You typed in an incorrect sorting string. Type again.");
} else if (!arrChoice.contains(breakArr[1])) {
System.out.println("You mistyped what can be sorted. Choose again from the list given. Follow exactly.");
} else {
String sendOut = breakArr[1] + " " + breakArr[2]; // we're sending, say "RID ASCENDING", or "RID DESCENDING." Watch.
System.out.println("THIS IS THE SENDOUT: " + sendOut);
return viewReviews(idToUse, gatherData, sendOut); // this completes the thing. It's fucking recursive.
}
}
}
}
}
public static int editReview(String rid) throws Exception {
Connection newConnect = getConnection();
Scanner editor = new Scanner(System.in);
Statement theReview = newConnect.createStatement();
String getReviewQuery = "SELECT shopping, connection_speed, comment, approval_status, station_name FROM Review WHERE passenger_ID='" + userID + "' AND rid='" + rid + "'";
ResultSet getReview = theReview.executeQuery(getReviewQuery);
String shoppingRate = "";
getReview.next();
for (int i = 0; i < Integer.parseInt(getReview.getString("shopping")); i++) {
shoppingRate = shoppingRate + "* ";
}
String connectionRate = "";
for (int i = 0; i < Integer.parseInt(getReview.getString("connection_speed")); i++) {
connectionRate = connectionRate + "* ";
}
System.out.println("REVIEW FOR: " + getReview.getString("station_name"));
System.out.println("APPROVAL STATUS: " + getReview.getString("approval_status"));
System.out.println("REVIEW ID: " + rid);
System.out.println("SHOPPING RATING: " + shoppingRate);
System.out.println("CONNECTION RATING: " + connectionRate);
System.out.println("COMMENT: " + getReview.getString("comment"));
System.out.println();
while (true) {
System.out.println("CHOOSE 1 TO EDIT REVIEW");
System.out.println("CHOOSE 2 TO DELETE REVIEW");
System.out.println("CHOOSE 3 TO RETURN TO VIEW REVIEWS");
System.out.print("ENTER CHOICE: ");
Scanner chooseOption = new Scanner(System.in);
int choiceEditString = chooseOption.nextInt();
if (choiceEditString == 1) {
int shoppingRating;
int connectionRating;
String commentLeft;
shoppingRating = -1; // assume we did get valid index, set shopping and connection ratings.
connectionRating = -1;
while(true) { // these smaller and smaller infinite loops restrict our errors, so making one error forces us to solve that
// one error before moving on, input-wise.
System.out.print("CHOOSE A SHOPPING RATING FROM 0 TO 5: ");
shoppingRating = chooseOption.nextInt();
if (shoppingRating < 0 || shoppingRating > 5) {
System.out.println("Choose a valid rating."); // valid check on shopping rating.
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user.
} else {
while(true) {
System.out.print("CHOOSE A CONNECTION RATING FROM 0 TO 5: "); // valid check on
connectionRating = chooseOption.nextInt();
if (connectionRating < 0 || connectionRating > 5) {
System.out.println("Choose a valid number");
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user.
} else {
System.out.println("userID: " + userID + " ROLE: " + (isAdmin ? "ADMIN" : "PASSENGER")); // this is a string that tells us the userID and passenger/admin role for a given user. // throwing identification everywhere so jackson doesn't get mad.
Scanner captureReview = new Scanner(System.in);
System.out.print("LEAVE A COMMENT ABOUT THE STATION (OPTIONAL): ");
commentLeft = captureReview.nextLine();
if (commentLeft.length() == 0 || commentLeft.equals("NULL")) {
commentLeft = "NULL";
}
String passQuery = "UPDATE Review SET shopping='" + shoppingRating + "', connection_speed='" + connectionRating + "', comment='" + commentLeft + "' WHERE passenger_ID='" + userID + "' AND rid='" + rid + "'";
//String passQuery = "INSERT INTO Review VALUES ('" + userID + "', " + count + ", " + shoppingRating + ", " + connectionRating +", '" + commentLeft + "', NULL, 'pending', NULL, '" + arrStations[getInt] + "')";
ResultSet rgstrSet = theReview.executeQuery(passQuery);
System.out.println("You updated a review.");
return 0;
// TODO: OBTAIN THE NEW RID BY GETTING ALL REVIEWS BY A PARTICULAR USER AND GETTING THE MAX
// NUMBER OF THOSE RIDS, ADD 1 TO GET THE NEW RID - IT'S A NEW REVIEW.
// TODO: WRITE THE QUERY TO ADD EVERYTHING AS A REVIEW TUPLE.
// TODO: TEST AND SEE IF THIS WORKS
// edit timestamp should be null
}
}
}
}
// System.out.println("HITTING LINE OUTSIDE BIG BLOCK, DONE WHEN EXIT TYPED IN USERNAME CHECK");
// return 0; // this should never hit.
} else if (choiceEditString == 2) {
Statement editcheck = newConnect.createStatement();
String passQuery = "DELETE FROM Review WHERE passenger_ID='" + userID + "' AND rid='" + rid + "'";
ResultSet editset = editcheck.executeQuery(passQuery);
String testQuery = "SELECT * FROM Review WHERE passenger_ID='" + userID + "' AND rid='" + rid + "'";
ResultSet testSet = editcheck.executeQuery(testQuery);
if (!(testSet.isBeforeFirst())) {
System.out.println("Congrats you deleted your review!");
System.out.println("------- RETURNING TO VIEW REVIEWS ------- ");
return 0;
} else {
System.out.println("Delete failed");
System.out.println("-------- RETURNING TO MAIN GUI, DELETE DIDN'T WORK ---------");
return 1;
}
} else if (choiceEditString == 3) {
System.out.println("You exited while editing review. Goodbye");
return 0;
} else {
System.out.println("You entered an incorrect number. Try again. Or quit.");
System.out.println("");
}
}
}
public static boolean checkIfNumeric(String checkString) {
try {
Integer.parseInt(checkString);
return true; // assumes that it did work.
} catch (NumberFormatException e) {
return false; // not numeric at all.
}
}
public static int stationDisplay(String stationName, Connection newConnect) throws Exception {
int approvedReviewsForStation = -1;
double avgShop = 0.0;
double avgConn = 0.0;
Connection getReviewsAddressEtc = newConnect;
String nameStation = stationName.trim();
Statement connectOnStation = newConnect.createStatement();
String[] twoArr = new String[2];
String address = null;
String status = null;
String avgShopping = "AVERAGE SHOPPING: ";
String avgConnSpeed = "AVG CONN SPEED: ";
String[][] reviewArr;
Scanner answerQuestion = new Scanner(System.in);
while(true) {
ArrayList<String> LinesList = new ArrayList<>(); // creates an array list to add names of lines.
String queryToGetStationInfo = "SELECT address, status FROM Station WHERE name='" + nameStation + "'";
String getLinesForStation = "SELECT line_name FROM Station_On_Line WHERE station_name='" + nameStation + "'";
String getReviewsForStation = "SELECT first_name, minit, last_name, shopping, connection_speed, comment FROM Review JOIN User WHERE passenger_ID = User.ID AND approval_status = 'approved' AND station_name='" + nameStation +"'";
String getCountReviews = "SELECT COUNT(connection_speed) FROM Review WHERE station_name='" + nameStation +"' AND approval_status='approved'";
String getAvgShoppingConn = "SELECT AVG(shopping), AVG(connection_speed) FROM Review WHERE station_name='" + nameStation + "' AND approval_status='approved'";
ResultSet StationInfoAddrStat = connectOnStation.executeQuery(queryToGetStationInfo); // address and info
ResultSet StationLines = connectOnStation.executeQuery(getLinesForStation); // get the line names
ResultSet ReviewsForStationAppr = connectOnStation.executeQuery(getReviewsForStation); // get the review info
ResultSet CountReviews = connectOnStation.executeQuery(getCountReviews); // get the counts
ResultSet Averages = connectOnStation.executeQuery(getAvgShoppingConn); // get the averages of conn and shopping
// ResultSet;
while(StationLines.next()) {
LinesList.add(StationLines.getString("line_name")); // add to LinesList all the lines.
}
while(StationInfoAddrStat.next()) { // get the address and status.
address = StationInfoAddrStat.getString("address");
status = StationInfoAddrStat.getString("status");
}
while (CountReviews.next()) { // get the counts of the reviews so that we can actually create the array.
approvedReviewsForStation = Integer.parseInt(CountReviews.getString("COUNT(connection_speed)"));
}
if (approvedReviewsForStation == 0) { // we'll have an empty array.
reviewArr = new String[approvedReviewsForStation + 1][6]; // create the array.
reviewArr[0][0] = "FIRST_NAME";
reviewArr[0][1] = "M.I.";
reviewArr[0][2] = "LAST_NAME";
reviewArr[0][3] = "SHOPPING"; // labeling categories.
reviewArr[0][4] = "CONNECTION_SPEED";
reviewArr[0][5] = "COMMENT";
int rowInt = 1;
int colInt = 1;
while (ReviewsForStationAppr.next()) {
if (rowInt > approvedReviewsForStation) {break;}
while(colInt <= 6) {
reviewArr[rowInt][colInt - 1] = ReviewsForStationAppr.getString(colInt);
colInt++;
}
rowInt++;
colInt = 1;
}
System.out.println("---------- LINE INFO ----------");
System.out.println("STATION NAME: " + nameStation); // print station name
System.out.println("STATUS: " + status); // print the status
System.out.println("ADDRESS: " + address); // print the address
System.out.println("LINES: " + LinesList.toString()); // print the regular lines
System.out.printf("%n%n"); // big new line
System.out.println("---------- REVIEWS ---------");
System.out.println(Arrays.deepToString(reviewArr).replace("], ", "]\n\n"));
System.out.printf("%n%n");
//System.out.println("TYPE IN 'EXIT', WITHOUT QUOTES, BECAUSE EVERYTHING IS EMPTY: ");
int lengthOfList = LinesList.size();
System.out.println("You can choose an index from the lines array, or type in EXIT to go back to the Reviews page.");
System.out.printf("MAKE A CHOICE: ");
String answerToQuest = answerQuestion.nextLine();
if (answerToQuest.equalsIgnoreCase("exit")) {
System.out.println("EXITING STATION DISPLAY");
return 0;
} else {
if (checkIfNumeric(answerToQuest) && Integer.parseInt(answerToQuest) >= 0 && Integer.parseInt(answerToQuest) < lengthOfList) { // assuming the answerToQuest is a valid int to pick from list.
lineDisplay(LinesList.get((int)(Integer.parseInt(answerToQuest))), newConnect, "REGULAR"); // goto line display.
} else {
System.out.println("WRONG CHOICE. PICK ANOTHER.");
}
}
// if (!answerQuestion.nextLine().equalsIgnoreCase("exit")) {
// System.out.println("Pick again.");
// } else {
// return 0;
// }
} else { // ASSUME A NON EMPTY ARRAY
reviewArr = new String[approvedReviewsForStation + 1][6]; // create the array.
reviewArr[0][0] = "FIRST_NAME";
reviewArr[0][1] = "M.I.";
reviewArr[0][2] = "LAST_NAME";
reviewArr[0][3] = "SHOPPING"; // labeling categories.
reviewArr[0][4] = "CONNECTION_SPEED";
reviewArr[0][5] = "COMMENT";
int rowInt = 1;
int colInt = 1;
while (ReviewsForStationAppr.next()) {
if (rowInt > approvedReviewsForStation) {break;}
while(colInt <= 6) {
reviewArr[rowInt][colInt - 1] = ReviewsForStationAppr.getString(colInt);
colInt++;
}
rowInt++;
colInt = 1;
}
while (Averages.next()) {
avgShop = Double.parseDouble(Averages.getString("AVG(shopping)")); // GET THE AVERAGE SHOPPING ASSUMING APPROVED REVIEWS ONLY
avgConn = Double.parseDouble(Averages.getString("AVG(connection_speed)")); // GET THE AVG CONNECTION_SPEED
}
System.out.println("STATION NAME: " + nameStation); // Station name
System.out.println("STATUS: " + status); // status to print out
System.out.println("LINES: " + LinesList.toString()); // available lines
System.out.printf("%n%n%n");
System.out.println(avgShopping + avgShop); // print the strings out
System.out.println(avgConnSpeed + avgConn); // print the strings out for avg connection and shopping
System.out.println(Arrays.deepToString(reviewArr).replace("], ", "]\n\n"));
System.out.printf("%n%n%n");
int lengthOfList = LinesList.size();
System.out.println("You can choose an index from the lines array, or type in EXIT to go back to the Reviews page.");
System.out.printf("MAKE A CHOICE: ");
String answerToQuest = answerQuestion.nextLine();
if (answerToQuest.equalsIgnoreCase("exit")) {
System.out.println("EXITING STATION DISPLAY");
return 0;
} else {
if (checkIfNumeric(answerToQuest) && Integer.parseInt(answerToQuest) >= 0 && Integer.parseInt(answerToQuest) < lengthOfList) { // assuming the answerToQuest is a valid int to pick from list.
lineDisplay(LinesList.get((int)(Integer.parseInt(answerToQuest))), newConnect, "REGULAR"); // goto line display.
} else {
System.out.println("WRONG CHOICE. PICK ANOTHER.");
}
}
}
}
}
public static int lineDisplay(String line, Connection newConnect, String addition) throws Exception {
System.out.printf("%n%n");
System.out.println("---------- LINE INFO ----------");
int numOfStops = -1; // set the numOfStops impossible
String nameLine = "Line NUMBER/NAME: "; // prep string
System.out.printf("%n%n");
System.out.println(nameLine + line);
Connection lineConn = newConnect; // bring connection in
Statement stateLine = newConnect.createStatement(); // create statement
String[][] displayArr; // the array that'll be displayed.
//String[] arrChoiceSort = new String[]{"station_name, order_number"};
Scanner anotherScan = new Scanner(System.in);
String queryToExec = null;
//ArrayList<String> checkChoiceList = new ArrayList<>(Arrays.asList(arrChoiceSort));
while(true) {
if (!(addition.equals("REGULAR"))) {
queryToExec = "SELECT station_name, order_number FROM Station_On_Line WHERE line_name='" + line + "' ORDER BY " + addition; // query to execute.
System.out.println("QUERY: " + queryToExec);
} else {
queryToExec = "SELECT station_name, order_number FROM Station_On_Line WHERE line_name='" + line + "'"; // query to execute.
}
String countQuery = "SELECT COUNT(station_name) FROM Station_On_Line WHERE line_name='" + line + "'"; // get the count.
ResultSet getStations = stateLine.executeQuery(queryToExec); // get the damn set.
ResultSet getCountStations = stateLine.executeQuery(countQuery); // get the count.
while(getCountStations.next()) {
numOfStops = Integer.parseInt(getCountStations.getString("COUNT(station_name)"));
}
displayArr = new String[numOfStops + 1][2]; // ADD 1 because we start 1 row below.
displayArr[0][0] = "STATION"; // you know what this is, basic setup.
displayArr[0][1] = "ORDER";
int rowInt = 1;
int colInt = 1;
System.out.println("---------- ARRAY ----------");
while (getStations.next()) {
if (rowInt > numOfStops) {break;}
while(colInt <= 2) {
displayArr[rowInt][colInt - 1] = getStations.getString(colInt);
colInt++;
}
rowInt++;
colInt = 1;
}
System.out.println(Arrays.deepToString(displayArr).replace("], ", "]\n\n"));
// be able to choose various things, such as the review and the station. Focus on this now.
System.out.println();
System.out.println("NUMBER OF STOPS: " + numOfStops);
System.out.println();
System.out.printf("Type in EXIT to get out of this page and back to the previous page, or specify sorting by typing SORT <category> ASC/DESC, respectively. <category> = station_name || order_number. CHOOSE: ");
String lineChoice = anotherScan.nextLine();
if (lineChoice.equalsIgnoreCase("EXIT")) {
return 0;
} else {
String[] choiceArr = lineChoice.split(" ");
if (choiceArr[0].trim().equalsIgnoreCase("sort") && (choiceArr[1].equals("station_name") || choiceArr[1].equals("order_number")) && (choiceArr[2].trim().equalsIgnoreCase("asc") || choiceArr[2].trim().equalsIgnoreCase("desc"))) {
String choiceMake = choiceArr[1] + " " + choiceArr[2]; // i'm not even going to check whether they typed the right thing
return lineDisplay(line, newConnect, choiceMake); // make this recursive to sort.
} else {
System.out.println("Type correctly next time.");
}