-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.java
1660 lines (1466 loc) · 53.4 KB
/
Menu.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
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
// File: Menu.java
// This program llustrates the use of a menu, which would be the basis
// for constructing a larger program by adding more options, where each
// option is handled by a separate function.
// This file is in the directory ~kdjackso/cs665
import java.sql.*;
import org.apache.derby.jdbc.ClientDriver;
import java.util.Scanner;
public class Menu
{
public static void main(String[] args)
{
int response;
Connection conn = null;
try
{
Driver d;
String url;
// Make a menu selection
response = 2;
while(response != 2035553){
response = PrintMenuAndGetResponse();
switch (response)
{
case 21:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=true";
conn = d.connect(url, null);
AddNewGamesExpansions(conn);
conn.close();
break;
case 22:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=true";
conn = d.connect(url, null);
AddNewAwardsWinners(conn);
conn.close();
break;
case 23:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=true";
conn = d.connect(url, null);
AddNewContribs(conn);
conn.close();
break;
case 24:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=true";
conn = d.connect(url, null);
NewRelease(conn);
conn.close();
break;
case 31:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
SearchWinnerbyYear(conn);
conn.close();
break;
case 32:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
SearchGamebyMech(conn);
conn.close();
break;
case 33:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
SearchExpbyBaseGame(conn);
conn.close();
break;
case 34:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
SearchGamebyCont(conn);
conn.close();
break;
case 35:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
SearchGamesWithContribSet(conn);
conn.close();
break;
case 36:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
CustomSearch(conn);
conn.close();
break;
case 37:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
top20(conn);
conn.close();
break;
case 38:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
mostpopbymech(conn);
conn.close();
break;
case 39:
d = new ClientDriver();
url = "jdbc:derby://localhost:2434/BoardGameDBase"
+ ";create=false";
conn = d.connect(url, null);
mostcomplex(conn);
conn.close();
break;
case 11:
System.out.println("Goodbye!");
return;
default: System.out.println("Illegal choice");
break;
}
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
// Removed disconnect for above custom connection stuffs
}
}
//Case 21
//This adds a new boardgame or boardgame expansion
public static void AddNewGamesExpansions(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
Scanner keyboard;
keyboard = new Scanner(System.in);
int choice = 0;
String Name = "";
int Year = 0;
int Time = 0;
int Age = 0;
int Max = 0;
int Min = 0;
int Sugg = 0;
int Base =0;
while(choice != 2035553) {
System.out.println("Would you like to:");
System.out.println("1. Add a new Game");
System.out.println("2. Add a new Expansion");
System.out.print("===>");
choice = keyboard.nextInt();
switch(choice)
{
case 1:
keyboard = new Scanner(System.in);
System.out.println("What is the name of the new Game?:");
System.out.print("===> ");
Name = keyboard.nextLine();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What Year was it Published?:");
System.out.print("===> ");
Year = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("How long does it take to play?:");
System.out.print("===> ");
Time = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the minimum age limit:");
System.out.print("===> ");
Age = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the maximum number of players?:");
System.out.print("===> ");
Max = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the minimum number of players?:");
System.out.print("===> ");
Min = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the suggested number of players?:");
System.out.print("===> ");
Sugg = keyboard.nextInt();
System.out.println();
String qry ="INSERT INTO BOARDGAMES (BGId, BGName, BGYearPublished, BGPlaytime, BGMinAge, BGMaxNumber, BGMinNumber, BGSuggestedNum)"
+ "VALUES ((select MAX(BGId)+1 FROM BOARDGAMES), '" + Name + "', " + Year + ", " + Time + ", " + Age + ", "
+ Max + ", " + Min + ", " + Sugg + ")";
int updated = stmt.executeUpdate(qry);
if (updated == 1)
{
System.out.println(Name + " added to table");
choice = 2035553;
}
else
{
System.out.println("Sorry, there was an error please try again");
}
break;
case 2:
//ask what letter the Base Game starts with
String letter = "";
System.out.print("What letter does the base game start with? ===>");
keyboard = new Scanner(System.in);
letter = keyboard.nextLine();
//print Games that start with that letter
String qry2 = "select BGId, BGName from BOARDGAMES where BGName like '" + letter + "%'";
ResultSet rs = stmt.executeQuery(qry2);
String last = "";
while (rs.next())
{
int BoardGameId = rs.getInt("BGId");
String BGName = rs.getString("BGName");
if(last == "")
{
last = BGName;
System.out.println(BoardGameId + ": " + BGName);
}
if(!BGName.equals(last))
{
System.out.println(BoardGameId + ": " + BGName);
last = BGName;
}
}
System.out.println();
rs.close();
//enter All other information just like above
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("Enter the IDNumber of the Base Game for this Expansion?:");
System.out.print("===> ");
Base = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the name of the new Expansion?:");
System.out.print("===> ");
Name = keyboard.nextLine();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What Year was it Published?:");
System.out.print("===> ");
Year = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("How long does it take to play?:");
System.out.print("===> ");
Time = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the minimum age limit:");
System.out.print("===> ");
Age = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the maximum number of players?:");
System.out.print("===> ");
Max = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the minimum number of players?:");
System.out.print("===> ");
Min = keyboard.nextInt();
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("What is the suggested number of players?:");
System.out.print("===> ");
Sugg = keyboard.nextInt();
System.out.println();
// INSERT INTO EXPANSIONS
qry ="INSERT INTO EXPANSIONS (EId, EName, EYearPublished, EPlaytime, EMinAge, EMaxNumber, EMinNumber, ESuggestedNum, BaseBGId)"
+ "VALUES ((select MAX(EId)+1 FROM EXPANSIONS), '" + Name + "', " + Year + ", " + Time + ", " + Age + ", "
+ Max + ", " + Min + ", " + Sugg + ", " + Base + ")";
updated = stmt.executeUpdate(qry);
if (updated == 1)
{
System.out.println(Name + " added to table");
choice = 2035553;
}
else
{
System.out.println("Sorry, there was an error please try again");
}
break;
default:
System.out.println("Sorry that was not a valid response, return to main menu");
choice = 2035553;
break;
}
}
}
// Case 22
// This adds an award to the list, automatically assigns it the next AId in the award table OR awards an award to a new winner/Year
public static void AddNewAwardsWinners(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
Scanner keyboard;
keyboard = new Scanner(System.in);
int choice = 0;
String award = "";
while(choice != 2035553) {
System.out.println("Would you like to:");
System.out.println("1. Add an Award to the database");
System.out.println("2. Add an Award Winner to the database");
System.out.print("===>");
choice = keyboard.nextInt();
switch(choice)
{
case 1:
keyboard = new Scanner(System.in);
System.out.println("What is the name of the new Award?:");
System.out.print("===> ");
award = keyboard.nextLine();
System.out.println();
String qry ="INSERT INTO AWARDS (AId, AName) VALUES ((select MAX(AId)+1 FROM AWARDS), '" + award + "')";
int updated = stmt.executeUpdate(qry);
if (updated == 1)
{
System.out.println(award + " added to table");
choice = 2035553;
}
else
{
System.out.println("Sorry, there was an error please try again");
}
break;
case 2:
//ask what letter the award name starts with
String letter = "";
System.out.print("What letter does the Award start with? ===>");
keyboard = new Scanner(System.in);
letter = keyboard.nextLine();
//print awards/AIds that start with that letter
String qry2 = "select AId, AName from AWARDS where AName like '" + letter + "%'";
ResultSet rs = stmt.executeQuery(qry2);
String last = "";
while (rs.next())
{
int AwardId = rs.getInt("AId");
String AwardName = rs.getString("AName");
if(last == "")
{
last = AwardName;
System.out.println(AwardId + ": " + AwardName);
}
if(!AwardName.equals(last))
{
System.out.println(AwardId + ": " + AwardName);
last = AwardName;
}
}
System.out.println();
System.out.print("Enter ID number of Award===>");
keyboard = new Scanner(System.in);
int Award = keyboard.nextInt();
System.out.println();
qry2 = "select * FROM AWARDS where AId = " + Award;
rs = stmt.executeQuery(qry2);
String AWName = "";
while(rs.next())
{
AWName = rs.getString("AName");
}
//ask what year of award/enter year
keyboard = new Scanner(System.in);
System.out.println("Enter the Year this was Awarded ===>:");
System.out.print("===> ");
int Year = keyboard.nextInt();
System.out.println();
//ask what letter game starts with
//print BG names and BGIds of games starting with that letter
System.out.print("What letter does the winning Game start with? ===>");
keyboard = new Scanner(System.in);
letter = keyboard.nextLine();
//print Games that start with that letter
qry2 = "select BGId, BGName from BOARDGAMES where BGName like '" + letter + "%'";
rs = stmt.executeQuery(qry2);
last = "";
while (rs.next())
{
int BoardGameId = rs.getInt("BGId");
String BGName = rs.getString("BGName");
if(last == "")
{
last = BGName;
System.out.println(BoardGameId + ": " + BGName);
}
if(!BGName.equals(last))
{
System.out.println(BoardGameId + ": " + BGName);
last = BGName;
}
}
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("Enter the IDNumber of the Game for this that won the award:");
System.out.print("===> ");
int Game = keyboard.nextInt();
System.out.println();
qry2 = "select * FROM BOARDGAMES where BGId = " + Game;
rs = stmt.executeQuery(qry2);
String BName = "";
while(rs.next())
{
BName = rs.getString("BGName");
}
qry ="INSERT INTO AWARDED (BoardGameId, AwardId, YearAwarded) VALUES (" + Game + ", " + Award + ", " + Year + ")";
updated = stmt.executeUpdate(qry);
if (updated == 1)
{
System.out.println(AWName + " for " + Year +" awarded to " + BName);
choice = 2035553;
}
else
{
System.out.println("Sorry, there was an error please try again");
}
break;
default:
System.out.println("Sorry that was not a valid response, return to main menu");
choice = 2035553;
break;
}
}
}
//Case 23
//this method is for Adding records to Creators and Contributors tables.
public static void AddNewContribs(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
Scanner keyboard;
keyboard = new Scanner(System.in);
int choice = 0;
String award = "";
while(choice != 2035553) {
System.out.println("Would you like to:");
System.out.println("1. Add a Creator to the database");
System.out.println("2. Assign a Creator a new Contribution");
System.out.print("===>");
choice = keyboard.nextInt();
switch(choice)
{
case 1:
keyboard = new Scanner(System.in);
System.out.println("What is the name of the Creator:");
System.out.print("===> ");
String Name = keyboard.nextLine();
System.out.println();
String qry ="INSERT INTO CREATOR (CId, CName) VALUES ((select MAX(CId)+1 FROM CREATOR), '" + Name + "')";
int updated = stmt.executeUpdate(qry);
if (updated == 1)
{
System.out.println(Name + " added to Creators table");
choice = 2035553;
}
else
{
System.out.println("Sorry, there was an error please try again");
}
break;
case 2:
//ask what letter the creator's name starts with
String letter = "";
System.out.print("What letter does the Creators name start with? ===>");
keyboard = new Scanner(System.in);
letter = keyboard.nextLine();
//print awards/AIds that start with that letter
String qry2 = "select CId, CName from CREATOR where CName like '" + letter + "%'";
ResultSet rs = stmt.executeQuery(qry2);
String last = "";
while (rs.next())
{
int CreatorId = rs.getInt("CId");
String CreatorName = rs.getString("CName");
if(last == "")
{
last = CreatorName;
System.out.println(CreatorId + ": " + CreatorName);
}
if(!CreatorName.equals(last))
{
System.out.println(CreatorId + ": " + CreatorName);
last = CreatorName;
}
}
System.out.println();
System.out.print("Enter ID number of Creator===>");
keyboard = new Scanner(System.in);
int Creator = keyboard.nextInt();
System.out.println();
qry2 = "select * FROM CREATOR where CId = " + Creator;
rs = stmt.executeQuery(qry2);
String CName = "";
while(rs.next())
{
CName = rs.getString("CName");
}
//ask what role that creator filled
keyboard = new Scanner(System.in);
System.out.println("What Role did this creator fill?");
System.out.println("1. Artist");
System.out.println("2. Designer");
System.out.print("===> ");
int Role = keyboard.nextInt();
System.out.println();
qry2 = "select Role from ROLES where RId = " + Role;
rs = stmt.executeQuery(qry2);
String RName = "";
while(rs.next())
{
RName = rs.getString("Role");
}
//ask what letter game starts with
//print BG names and BGIds of games starting with that letter
System.out.print("What letter does the Game start with? ===>");
keyboard = new Scanner(System.in);
letter = keyboard.nextLine();
//print Games that start with that letter
qry2 = "select BGId, BGName from BOARDGAMES where BGName like '" + letter + "%'";
rs = stmt.executeQuery(qry2);
last = "";
String BGName = "";
while (rs.next())
{
int BoardGameId = rs.getInt("BGId");
BGName = rs.getString("BGName");
if(last == "")
{
last = BGName;
System.out.println(BoardGameId + ": " + BGName);
}
if(!BGName.equals(last))
{
System.out.println(BoardGameId + ": " + BGName);
last = BGName;
}
}
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("Enter the IDNumber of the Game for this that won the award:");
System.out.print("===> ");
int Game = keyboard.nextInt();
System.out.println();
qry2 = "select BGName from BOARDGAMES where BGId = " + Game;
rs = stmt.executeQuery(qry2);
while(rs.next())
{
BGName = rs.getString("BGName");
}
qry ="INSERT INTO CONTRIBUTORS (RoleId, CreatorId, BoardgameId) VALUES (" + Role + ", " + Creator + ", " + Game + ")";
updated = stmt.executeUpdate(qry);
if (updated == 1)
{
System.out.println(CName + " added as " + RName + " for " + BGName);
choice = 2035553;
}
else
{
System.out.println("Sorry, there was an error please try again");
}
break;
default:
System.out.println("Sorry that was not a valid response, return to main menu");
choice = 2035553;
break;
}
}
}
// Case 24
// This method is for adding new Releases of existing boardgames
public static void NewRelease(Connection conn) throws SQLException
{
//ask what letter game starts with
//print BG names and BGIds of games starting with that letter
Statement stmt = conn.createStatement();
Scanner keyboard;
ResultSet rs;
String qry = "";
String qry2 = "";
String letter = "";
System.out.print("What letter does the Game start with? ===>");
keyboard = new Scanner(System.in);
letter = keyboard.nextLine();
//print Games that start with that letter
qry2 = "select BGId, BGName from BOARDGAMES where BGName like '" + letter + "%'";
rs = stmt.executeQuery(qry2);
String last = "";
String BGName = "";
while (rs.next())
{
int BoardGameId = rs.getInt("BGId");
BGName = rs.getString("BGName");
if(last == "")
{
last = BGName;
System.out.println(BoardGameId + ": " + BGName);
}
if(!BGName.equals(last))
{
System.out.println(BoardGameId + ": " + BGName);
last = BGName;
}
}
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("Enter the IDNumber of the Game you are adding a release for:");
System.out.print("===> ");
int Game = keyboard.nextInt();
System.out.println();
qry2 = "select BGName from BOARDGAMES where BGId = " + Game;
rs = stmt.executeQuery(qry2);
while(rs.next())
{
BGName = rs.getString("BGName");
}
// Get the language of the release
qry2 = "select LId, Language from Languages";
rs = stmt.executeQuery(qry2);
last = "";
String Lang = "";
while (rs.next())
{
int LangId = rs.getInt("LId");
Lang = rs.getString("Language");
if(last == "")
{
last = Lang;
System.out.println(LangId + ": " + Lang);
}
if(!Lang.equals(last))
{
System.out.println(LangId + ": " + Lang);
last = Lang;
}
}
System.out.println();
keyboard = new Scanner(System.in);
System.out.println("Enter the IDNumber of the Language for this release");
System.out.print("===> ");
int LangNum = keyboard.nextInt();
System.out.println();
qry2 = "select Language from LANGUAGES where LId = " + LangNum;
rs = stmt.executeQuery(qry2);
while(rs.next())
{
Lang = rs.getString("Language");
}
qry ="INSERT INTO RELEASES (BoardgameId, LanguageId) VALUES (" + Game + ", " + LangNum + ")";
int updated = stmt.executeUpdate(qry);
if (updated == 1)
{
System.out.println("A release of " + BGName + " in " + Lang + " has been added ");
}
else
{
System.out.println("Sorry, there was an error please try again");
}
}
// Case 31
// This method is for the query of board game by award+year
public static void SearchWinnerbyYear(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
Scanner keyboard;
int response = 2;
String award = "";
while(response != 2035553){
keyboard = new Scanner(System.in);
System.out.println("Type an award name for a wildcard search:");
System.out.print("Your choice ==> ");
award = keyboard.nextLine();
System.out.println( );
keyboard = new Scanner(System.in);
System.out.println("Type a winning year:");
System.out.print("Your choice ==> ");
response = keyboard.nextInt();
System.out.println( );
String qry = "select bgname, aname, yearawarded "
+ "from boardgames, awards, awarded ";
qry += "where aname like '" + award + "%'";
qry += " and aid = AwardId and yearawarded = " + response;
qry += " and bgid = BoardgameId";
qry += " order by aname";
ResultSet rs = stmt.executeQuery(qry);
// Step 3: loop through the result set
String last = "";
while (rs.next())
{
String yearawarded = rs.getString("yearawarded");
String bgname = rs.getString("BGName");
String aname = rs.getString("aname");
if(last == "")
{
last = aname;
System.out.println(yearawarded + ": " + aname);
}
if(!aname.equals(last))
{
System.out.println(yearawarded + ": " + aname);
last = aname;
}
System.out.println("\tWinner: " + bgname);
}
System.out.println( );
rs.close();
break;
}
}
// Case 32
// This method is for querying board game mechanisms
public static void SearchGamebyMech(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
Scanner keyboard;
int response = 2;
String mech = "";
while(response != 2035553){
keyboard = new Scanner(System.in);
System.out.println("Type a mechanism for a wildcard search:");
System.out.print("Your choice ==> ");
mech = keyboard.nextLine();
System.out.println( );
String qry = "select distinct bgname "
+ "from boardgames, mechanics, mechanisms ";
qry += "where mechanism like '" + mech + "%'";
qry += " and mid = mechanismid and bgid = BoardgameId";
qry += " order by bgname";
ResultSet rs = stmt.executeQuery(qry);
// Step 3: loop through the result set
while (rs.next())
{
String bgname = rs.getString("BGName");
System.out.println("\t" + bgname);
}
System.out.println( );
rs.close();
break;
}
}
// Case 33
// This method is for the query for expansions from a base game
public static void SearchExpbyBaseGame(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
Scanner keyboard;
int response = 2;
while(response != 2035553){
keyboard = new Scanner(System.in);
System.out.println("Choose from one of the following options:");
System.out.println(" 1. Type full board game name.\n");
System.out.println(" 2. Type beginning of name (wildcard Beginn*).\n");
System.out.print("Your choice ==> ");
response = keyboard.nextInt();
System.out.println( );
if(response != 1 && response != 2)
continue;
keyboard = new Scanner(System.in);
String bgname;
System.out.println("Enter the board game name: ");
System.out.print("Your choice ==> ");
bgname = keyboard.nextLine();
System.out.println( );
String qry = "select distinct ename "
+ "from boardgames, expansions ";
if(response == 1) // Full name
{
qry += "where bgname = '" + bgname + "'";
}
else // Beginning of name
{
qry += "where bgname like '" + bgname + "%'";
}
qry += " and bgid = basebgid";
qry += " order by ename";
ResultSet rs = stmt.executeQuery(qry);
// Step 3: loop through the result set
while (rs.next())
{
String expname = rs.getString("EName");
System.out.println("\t" + expname);
}
System.out.println( );
rs.close();
break;
}
}
// Case 34
// This method is for the query of games by creator
public static void SearchGamebyCont(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
Scanner keyboard;
int response = 2;
String award = "";
int role = 0;
String contributor = "";
while(response != 2035553){
keyboard = new Scanner(System.in);
System.out.println("What creator are you interested in?");
System.out.println("(Just type the beginning of a wildcard search)");
System.out.print("Your choice ==> ");
contributor = keyboard.nextLine();
System.out.println( );
while(response != 2035553){
keyboard = new Scanner(System.in);
System.out.println(contributor + " as?");
System.out.println(" 1. Artist\n");
System.out.println(" 2. Designer\n");
System.out.println(" 3. Neither\n");
System.out.print("Your choice ==> ");
response = keyboard.nextInt();
System.out.println( );
if(response == 3)
break;
if(response < 0 || response > 2)
continue;
role = response;
break;
}
break;
}
String qry = "select distinct bgname, cname "
+ "from boardgames";
qry += ", contributors as c, creator, roles";
qry += " where cname like '" + contributor + "%'";
if(response != 3)
qry += " and rid = " + role;
qry += " and CId = CreatorId and c.BoardgameId = BGId";
qry += " order by cname";
ResultSet rs = stmt.executeQuery(qry);
// Step 3: loop through the result set
String last = "";
while (rs.next())
{
String cname = rs.getString("cname");
if(last == "")
{
last = cname;
System.out.println(cname + ":");
}
if(!cname.equals(last))
{
System.out.println(cname + ":");
last = cname;
}
String bgname = rs.getString("bgname");
System.out.println("\t" + bgname);
}
System.out.println( );
rs.close();
}
// Case 35
// This method is for the query of games with the same contributors
public static void SearchGamesWithContribSet(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
Scanner keyboard;