-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMediaManager.java
1748 lines (1491 loc) · 49.8 KB
/
MediaManager.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
/* @st20102906 1.0 06/12/2016
*
* Matthew Aaron Roberts, 2016
* Student number: st20102906
*/
package st20102906;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
/**
* MediaManager.java - the class consists exclusively of static methods that
* allows a user to catalogue various forms of media, including films, audio
* tracks and television programmes.
*
* The user is provided with a menu system, with which they can use to
* navigate and perform a number of operations. These operations include the
* ability to add, edit, delete and search for a film, audio track or
* television programme.
*
* @author Matthew Roberts
* @version 1.0
*/
public class MediaManager{
// declares a global media collection
private static MediaCollection mediaCollection;
// declares global scanner to receive input from the user
private static Scanner sGet = new Scanner(System.in);
/**
* Initialise Media Collection with test data, call Home Screen and call
* exit method once Home Screen has finished.
* @param args
*/
public static void main(String[] args)
{
// call initialisation
init();
// call home screen
screenHome();
// call exit once finished with home screen
exit();
}
/**
* Creates a collection of media objects and populate the media collection
* with test data.
*/
private static void init()
{
// load test data into lists of the corresponding objects.
ArrayList<Film> films = Testing_DataLoader.loadFilms();
ArrayList<AudioTrack> audioTracks = Testing_DataLoader.loadAudioTracks();
ArrayList<TelevisionProgramme> televisionProgrammes = Testing_DataLoader.loadTelevisionProgrammes();
// initialise Media Collection and add the test data.
mediaCollection = new MediaCollection(films, audioTracks, televisionProgrammes);
}
/**
* Main program loop. Displays Home screen menu, receives input from the
* user and directs user to new screens depending on input decision.
*/
private static void screenHome()
{
int input = 0;
// repeat until user specifies to exit the program
while (input!=5)
{
displayHeader();
// display home screen menu
System.out.println("1. Add a new media item");
System.out.println("2. Search media items");
System.out.println("3. List view media items");
System.out.println("4. Randomly select media item");
System.out.println("5. Exit\n");
// get home screen menu input
System.out.print(" > ");
input = convertStringToInt();
// make home screen menu decision
if (input==5)
break;
else if (input==4)
randomMedia();
else if (input==3)
screenViewMedia();
else if (input==2)
screenSearchMedia();
else if (input==1)
screenAddMedia();
else
System.out.println("Invalid option: Enter a number (1-5)!");
}
}
/**
* Add Media loop. Displays Add media menu, receives input from the user and
* directs user to either add film, audio track or television programme.
*/
private static void screenAddMedia()
{
int input = 0;
// repeat until user enters a valid menu option
while (!((input<=4)&&(input>=1)))
{
displayHeader();
// display menu
System.out.println("Add to a media type:");
System.out.println("1. Film");
System.out.println("2. Audio Track");
System.out.println("3. Television Programme");
System.out.println("4. Back\n");
// get input
System.out.print(" > ");
input = convertStringToInt();
// menu decision
if (input==4)
break;
else if (input==3)
addTelevisionProgramme();
else if (input==2)
addAudioTrack();
else if (input==1)
addFilm();
else
System.out.println("Invalid option: Enter a number (1-4)!");
}
}
/**
* Loops until user confirms that the data they added is correct. Prompts
* the user to input attribute data for a Film.
*/
private static void addFilm()
{
String input = "n";
String title = null;
int yearOfRelease = 0;
double duration = 0.0;
String studio = null;
String director = null;
int rating = 0;
// decision to loop unless user is confident with input data
while (!(input.equals("y") || input.equals("Y")))
{
displayHeader();
// prompts the user for input for the Film
System.out.println("Input Film:- ");
System.out.print(" - Title:\n > ");
title = sGet.nextLine();
System.out.print(" - Year of Release:\n > ");
yearOfRelease = convertStringToInt();
System.out.print(" - Duration(minutes):\n > ");
duration = convertStringToDouble();
System.out.print(" - Studio:\n > ");
studio = sGet.nextLine();
System.out.print(" - Director:\n > ");
director = sGet.nextLine();
System.out.print(" - Rating(1-5):\n > ");
rating = convertStringToInt();
// get loop decision
System.out.println("\nDetails correct? (Y/N)");
System.out.print(" > ");
input = sGet.nextLine();
}
// add Film with entered attribute values, to media collection.
mediaCollection.addFilm(title, yearOfRelease, duration, studio, director, rating);
System.out.println("\nSuccessfully added to the system!\n");
System.out.println("..Press Enter to return to Homescreen..");
sGet.nextLine();
}
/**
* Loops until user confirms that the data they added is correct. Prompts
* the user to input attribute data for an Audio Track.
*/
private static void addAudioTrack()
{
String input = "n";
String title = null;
String creator = null;
int yearOfRelease = 0;
double duration = 0.0;
String recordLabel = null;
int rating = 0;
while (!(input.equals("y") || input.equals("Y")))
{
displayHeader();
System.out.println("Input Audio Track:- ");
System.out.print(" - Title:\n > ");
title = sGet.nextLine();
System.out.print(" - Creators:\n > ");
creator = sGet.nextLine();
System.out.print(" - Year of Release:\n > ");
yearOfRelease = convertStringToInt();
System.out.print(" - Duration(minutes):\n > ");
duration = convertStringToDouble();
System.out.print(" - Record Label:\n > ");
recordLabel = sGet.nextLine();
System.out.print(" - Rating(1-5):\n > ");
rating = convertStringToInt();
System.out.println("\nDetails correct? (Y/N)");
System.out.print(" > ");
input = sGet.nextLine();
}
mediaCollection.addAudioTrack(title, creator, yearOfRelease, duration, recordLabel, rating);
System.out.println("\nSuccessfully added to the system!\n");
System.out.println("..Press Enter to return to Homescreen..");
sGet.nextLine();
}
/**
* Loops until user confirms that the data they added is correct. Prompts
* the user to input attribute data for a Television Programme.
*/
private static void addTelevisionProgramme()
{
String input = "n";
String title = null;
int series = 0;
int episode = 0;
int yearOfRelease = 0;
String studio = null;
String channel = null;
int rating = 0;
while (!(input.equals("y") || input.equals("Y")))
{
displayHeader();
System.out.println("Input Television Programme:- ");
System.out.print(" - Title:\n > ");
title = sGet.nextLine();
System.out.print(" - Series:\n > ");
series = convertStringToInt();
System.out.print(" - Episode:\n > ");
episode = convertStringToInt();
System.out.print(" - Year of Release:\n > ");
yearOfRelease = convertStringToInt();
System.out.print(" - Studio:\n > ");
studio = sGet.nextLine();
System.out.print(" - Channel:\n > ");
channel = sGet.nextLine();
System.out.print(" - Rating(1-5):\n > ");
rating = convertStringToInt();
System.out.println("\nDetails correct? (Y/N)");
System.out.print(" > ");
input = sGet.nextLine();
}
mediaCollection.addTelevisionProgramme(title, series, episode, yearOfRelease, studio, channel, rating);
System.out.println("\nSuccessfully added to the system!\n");
System.out.println("..Press Enter to return to Homescreen..");
sGet.nextLine();
}
/**
* Search Media loop. Displays Search Media menu, receives input form the user
* and directs user to either search film, audio track or television programme.
*/
private static void screenSearchMedia()
{
int input = 0;
// repeat until user enters a valid menu option
while (!(input<=4 && input>=1))
{
displayHeader();
// display menu
System.out.println("Search a media type:");
System.out.println("1. Films");
System.out.println("2. Audio Tracks");
System.out.println("3. Television Programmes");
System.out.println("4. Back\n");
// get user input
System.out.print(" > ");
input = convertStringToInt();
// make decision depending on user input
if (input==4)
break;
else if (input==3)
searchTelevisionProgramme();
else if (input==2)
searchAudioTrack();
else if (input==1)
searchFilm();
else
System.out.println("Invalid option: Enter a number (1-4)!");
}
}
/**
* Searches through Media Collection's list of Films, if an attribute matches then
* it adds it to a new list of Films. Displays the new list as results and offers
* the user to either, search again or select one of the resultant Films.
*/
private static void searchFilm()
{
// creates a temporary list of films from the stored films within media collection
ArrayList<Film> films = mediaCollection.getFilms();
// creates an empty list for films
ArrayList<Film> results = new ArrayList<Film>();
String result = null;
int inAttributeMenu = 0;
int inResultsMenu = 0;
String inputTitle;
int inputYearOfRelease;
double inputDuration;
String inputStudio;
String inputDirector;
int inputRating;
/*
* repeat while: -
* - out of scope of the menu options
* - if user doesn't enter 7
* - if user doesn't select a film
*/
do
{
inAttributeMenu = 0;
results.clear();
result = null;
// repeats until user enters a number between 7 and 1
while (!((inAttributeMenu<=7)&&(inAttributeMenu>=1)))
{
displayHeader();
System.out.println("Specify Film attribute:");
System.out.println("1. Title");
System.out.println("2. Year of Release");
System.out.println("3. Duration");
System.out.println("4. Studio");
System.out.println("5. Director");
System.out.println("6. Rating");
System.out.println("7. Back\n");
System.out.print(" > ");
inAttributeMenu = convertStringToInt();
/*
* inside options 1-6:-
* - prompt user for input
* - get input from user
* - search through films for matching rating
* - if a match is found: add film to array list
*/
if (inAttributeMenu==7)
break;
else if (inAttributeMenu==6)
{
// prompt the user for input
System.out.println("Type a Film 'Rating':\n");
System.out.print(" > ");
// get input from user
inputRating = convertStringToInt();
// search through films for matching rating
for (Film film : films)
{
// if match found: add film to array list
if (inputRating==film.getRating())
{
results.add(film);
}
}
}
else if (inAttributeMenu==5)
{
System.out.println("Type a Film 'Director':\n");
System.out.print(" > ");
inputDirector = sGet.nextLine();
for (Film film : films)
{
if (inputDirector.equals(film.getDirector()))
{
results.add(film);
}
}
}
else if (inAttributeMenu==4)
{
System.out.println("Type a Film 'Studio':\n");
System.out.print(" > ");
inputStudio = sGet.nextLine();
for (Film film : films)
{
if (inputStudio.equals(film.getStudio()))
{
results.add(film);
}
}
}
else if (inAttributeMenu==3)
{
System.out.println("Type a Film 'Duration(minutes)':\n");
System.out.print(" > ");
inputDuration = convertStringToDouble();
for (Film film : films)
{
if (inputDuration==film.getDuration())
{
results.add(film);
}
}
}
else if (inAttributeMenu==2)
{
System.out.println("Type a Film 'Year of Release':\n");
System.out.print(" > ");
inputYearOfRelease = convertStringToInt();
for (Film film : films)
{
if (inputYearOfRelease==film.getYearOfRelease())
{
results.add(film);
}
}
}
else if (inAttributeMenu==1)
{
System.out.println("Type a Film 'Title':\n");
System.out.print(" > ");
inputTitle = sGet.nextLine();
for (Film film : films)
{
if (inputTitle.equals(film.getTitle()))
{
results.add(film);
}
}
}
else
System.out.println("Invalid option: Enter a number (1-7)!");
} // end while loop
if (inAttributeMenu!=7)
{
displayHeader();
// display all the results with matching values
System.out.println("Found " + results.size() + " results");
for (int i = 0; i<results.size(); i++)
{
result = (results.get(i).getTitle() + " (" + results.get(i).getYearOfRelease() + ")");
System.out.println((i+1) + ". Select \'" + result + "\'");
}
// depending on the number of results, add two menu options afterwards
System.out.println((results.size()+1) + ". Search again");
System.out.println((results.size()+2) + ". Return to Homescreen\n");
// get user input
System.out.print(" > ");
inResultsMenu = convertStringToInt();
/*
* depending on the number of results, check if the user entered a
* value outside the scope of the menu options
*/
if (inResultsMenu<1 || inResultsMenu>(results.size()+2))
System.out.println("Invalid option: Enter a number (1-" + (results.size()+2) + ")");
}
/*
* repeat while: -
* - out of scope of the menu options
* - if user didn't previously enter 7
* - if user didn't select a film
*/
} while((inResultsMenu==(results.size()+1) || (inResultsMenu<1 || inResultsMenu>(results.size()+2))) && !(inAttributeMenu==7) );
// if user selects a film, call method selectFilm with the parameter of selected film
if (inResultsMenu>0 && inResultsMenu<=results.size())
selectFilm(results.get(inResultsMenu-1));
if (inAttributeMenu==7)
screenSearchMedia();
}
/**
* Searches through Media Collection's list of Audio Tracks, if an attribute matches
* then it adds it to a new list of Audio Tracks. Displays the new list as results
* and offers the user to either, search again or select one of the resultant
* Audio Tracks.
*/
private static void searchAudioTrack()
{
/*
* creates a temporary list of audio tracks from the stored audio tracks within
* media collection
*/
ArrayList<AudioTrack> audioTracks = mediaCollection.getAudioTracks();
// creates an empty list for audio tracks
ArrayList<AudioTrack> results = new ArrayList<AudioTrack>();
String result = null;
int inAttributeMenu = 0;
int inResultsMenu = 0;
String inputTitle;
String inputCreator;
int inputYearOfRelease;
double inputDuration;
String inputRecordLabel;
int inputRating;
do
{
inAttributeMenu = 0;
results.clear();
result = null;
while (!((inAttributeMenu<=7)&&(inAttributeMenu>=1)))
{
displayHeader();
System.out.println("Specify Audio Track attribute:");
System.out.println("1. Title");
System.out.println("2. Creator");
System.out.println("3. Year of Release");
System.out.println("4. Duration(seconds)");
System.out.println("5. Record Label");
System.out.println("6. Rating");
System.out.println("7. Back\n");
System.out.print(" > ");
inAttributeMenu = convertStringToInt();
if (inAttributeMenu==7)
break;
else if (inAttributeMenu==6)
{
System.out.println("\nEnter an Audio Track 'Rating':");
System.out.print(" > ");
inputRating = convertStringToInt();
for (AudioTrack audioTrack : audioTracks)
{
if (inputRating==audioTrack.getRating())
{
results.add(audioTrack);
}
}
}
else if (inAttributeMenu==5)
{
System.out.println("\nEnter an Audio Track 'Record Label':");
System.out.print(" > ");
inputRecordLabel = sGet.nextLine();
for (AudioTrack audioTrack : audioTracks)
{
if (inputRecordLabel.equals(audioTrack.getRecordLabel()))
{
results.add(audioTrack);
}
}
}
else if (inAttributeMenu==4)
{
System.out.println("\nEnter an Audio Track 'Duration(minutes)':");
System.out.print(" > ");
inputDuration = convertStringToDouble();
for (AudioTrack audioTrack : audioTracks)
{
if (inputDuration==audioTrack.getDuration())
{
results.add(audioTrack);
}
}
}
else if (inAttributeMenu==3)
{
System.out.println("\nEnter an Audio Track 'Year of Release':");
System.out.print(" > ");
inputYearOfRelease = convertStringToInt();
for (AudioTrack audioTrack : audioTracks)
{
if (inputYearOfRelease==audioTrack.getYearOfRelease())
{
results.add(audioTrack);
}
}
}
else if (inAttributeMenu==2)
{
System.out.println("\nEnter an Audio Track 'Creator':");
System.out.print(" > ");
inputCreator = sGet.nextLine();
for (AudioTrack audioTrack : audioTracks)
{
if (inputCreator.equals(audioTrack.getCreator()))
{
results.add(audioTrack);
}
}
}
else if (inAttributeMenu==1)
{
System.out.println("\nEnter an Audio Track 'Title':");
System.out.print(" > ");
inputTitle = sGet.nextLine();
for (AudioTrack audioTrack : audioTracks)
{
if (inputTitle.equals(audioTrack.getTitle()))
{
results.add(audioTrack);
}
}
}
else
System.out.println("Invalid option: Enter a number (1-7)!");
}
if (!(inAttributeMenu==7))
{
displayHeader();
System.out.println("Found " + results.size() + " results");
for (int i = 0; i<results.size(); i++)
{
result = (results.get(i).getTitle() + " (" + results.get(i).getYearOfRelease() + ")");
System.out.println((i+1) + ". Select \'" + result + "\'");
}
System.out.println((results.size()+1) + ". Search again");
System.out.println((results.size()+2) + ". Return to Homescreen\n");
System.out.print(" > ");
inResultsMenu = convertStringToInt();
if (inResultsMenu<1 || inResultsMenu>(results.size()+2))
System.out.println("Invalid option: Enter a number (1-" + (results.size()+2) + ")");
}
} while((inResultsMenu==(results.size()+1) || (inResultsMenu<1 || inResultsMenu>(results.size()+2))) && !(inAttributeMenu==7) );
if (inResultsMenu>0 && inResultsMenu<=results.size())
selectAudioTrack(results.get(inResultsMenu-1));
if (inAttributeMenu==7)
screenSearchMedia();
}
/**
* Searches through Media Collection's list of Television Programmes, if an
* attribute matches then it adds it to a new list of Television Programmes.
* Displays the new list as results and offers the user to either, search
* again or select one of the resultant Television Programmes.
*/
private static void searchTelevisionProgramme()
{
ArrayList<TelevisionProgramme> televisionProgrammes = mediaCollection.getTelevisionProgrammes();
ArrayList<TelevisionProgramme> results = new ArrayList<TelevisionProgramme>();
String result = null;
int inAttributeMenu = 0;
int inResultsMenu = 0;
String inputTitle;
int inputSeries;
int inputEpisode;
int inputYearOfRelease;
String inputStudio;
String inputChannel;
int inputRating;
do
{
inAttributeMenu = 0;
results.clear();
result = null;
while (!((inAttributeMenu<=7)&&(inAttributeMenu>=1)))
{
displayHeader();
System.out.println("Specify Television Programme attribute:");
System.out.println("1. Title");
System.out.println("2. Series");
System.out.println("3. Episode");
System.out.println("4. Year of Release");
System.out.println("5. Studio");
System.out.println("6. Channel");
System.out.println("7. Rating");
System.out.println("8. Back\n");
System.out.print(" > ");
inAttributeMenu = convertStringToInt();
if (inAttributeMenu==8)
break;
else if (inAttributeMenu==7)
{
System.out.println("\nEnter a Television Programme 'Rating':");
System.out.print(" > ");
inputRating = convertStringToInt();
for (TelevisionProgramme televisionProgramme : televisionProgrammes)
{
if (inputRating==televisionProgramme.getRating())
{
results.add(televisionProgramme);
}
}
}
else if (inAttributeMenu==6)
{
System.out.println("\nEnter a Television Programme 'Channel':");
System.out.print(" > ");
inputChannel = sGet.nextLine();
for (TelevisionProgramme televisionProgramme : televisionProgrammes)
{
if (inputChannel.equals(televisionProgramme.getChannel()))
{
results.add(televisionProgramme);
}
}
}
else if (inAttributeMenu==5)
{
System.out.println("\nEnter a Television Programme 'Studio':");
System.out.print(" > ");
inputStudio = sGet.nextLine();
for (TelevisionProgramme televisionProgramme : televisionProgrammes)
{
if (inputStudio.equals(televisionProgramme.getStudio()))
{
results.add(televisionProgramme);
}
}
}
else if (inAttributeMenu==4)
{
System.out.println("\nEnter a Television Programme 'Year of Release':");
System.out.print(" > ");
inputYearOfRelease = convertStringToInt();
for (TelevisionProgramme televisionProgramme : televisionProgrammes)
{
if (inputYearOfRelease==televisionProgramme.getYearOfRelease())
{
results.add(televisionProgramme);
}
}
}
else if (inAttributeMenu==3)
{
System.out.println("\nEnter a Television Programme 'Episode':");
System.out.print(" > ");
inputEpisode = convertStringToInt();
for (TelevisionProgramme televisionProgramme : televisionProgrammes)
{
if (inputEpisode==televisionProgramme.getEpisode())
{
results.add(televisionProgramme);
}
}
}
else if (inAttributeMenu==2)
{
System.out.println("\nEnter a Television Programme 'Series':");
System.out.print(" > ");
inputSeries = convertStringToInt();
for (TelevisionProgramme televisionProgramme : televisionProgrammes)
{
if (inputSeries==televisionProgramme.getSeries())
{
results.add(televisionProgramme);
}
}
}
else if (inAttributeMenu==1)
{
System.out.println("\nEnter a Television Programme 'Title':");
System.out.print(" > ");
inputTitle = sGet.nextLine();
for (TelevisionProgramme televisionProgramme : televisionProgrammes)
{
if (inputTitle.equals(televisionProgramme.getTitle()))
{
results.add(televisionProgramme);
}
}
}
else
System.out.println("Invalid option: Enter a number (1-8)!");
}
if (!(inAttributeMenu==8))
{
displayHeader();
System.out.println("Found " + results.size() + " results");
for (int i = 0; i<results.size(); i++)
{
result = (results.get(i).getTitle() + " (" + results.get(i).getYearOfRelease() + ")");
System.out.println((i+1) + ". Select \'" + result + "\'");
}
System.out.println((results.size()+1) + ". Search again");
System.out.println((results.size()+2) + ". Return to Homescreen\n");
System.out.print(" > ");
inResultsMenu = convertStringToInt();
if (inResultsMenu<1 || inResultsMenu>(results.size()+2))
System.out.println("Invalid option: Enter a number (1-" + (results.size()+2) + ")");
} // end while loop
} while((inResultsMenu==(results.size()+1) || (inResultsMenu<1 || inResultsMenu>(results.size()+2))) && !(inAttributeMenu==8) );
if (inResultsMenu>0 && inResultsMenu<=results.size())
selectTelevisionProgramme(results.get(inResultsMenu-1));
if (inAttributeMenu==8)
screenSearchMedia();
}
/**
* Offers the user with a menu option to choose which media type the user wishes to
* view details for.
*/
private static void screenViewMedia()
{
int input = 0;
// return here after choice
while (input!=5)
{
displayHeader();
System.out.println("Select a List View");
System.out.println("1. Films");
System.out.println("2. Audio Tracks");
System.out.println("3. Television Programmes");
System.out.println("4. View all");
System.out.println("5. Back\n");
System.out.print(" > ");
input = convertStringToInt();
if (input==5)
break;
else if (input==4)
viewListAll();
else if (input==3)
viewListTelevisionProgrammes();
else if (input==2)
viewListAudioTracks();
else if (input==1)
viewListFilms();
else
System.out.println("Invalid option: Enter a number (1-5)!");
}
}
/**
* Displays a table-like display of all Films stored in Media Collection. Formats text
* to keep within the bounds of the table.
*/
private static void viewListFilms()
{
// get a list of films from media collection's list of films
ArrayList<Film> films = mediaCollection.getFilms();
displayHeader();
String title = null;
int yearOfRelease = 0;
int rating = 0;
// all media types have three attributes in common; title, year of release, and rating
System.out.println("╔══════════════╦═══════════════╦══════╗");
System.out.println("║Title ║Year of Release║Rating║");
System.out.println("╠══════════════╩═══════╤═══════╬══════╣");
// display a table-like display of all films
for (Film film : films)
{
title = film.getTitle();
yearOfRelease = film.getYearOfRelease();
rating = film.getRating();
/* change format of the title so that the text stays within the table-like display
* if the title is longer than 20 characters, remove any characters after and change
* the last two for two periods '..'.
*/
if (title.length()>20)
{
System.out.format("║%.20s..│ %4d ║ %d/5 ║\n", title, yearOfRelease, rating);
}
else
{
System.out.format("║%-22s│ %4d ║ %d/5 ║\n", title, yearOfRelease, rating);
}
}
System.out.println("╚══════════════════════╧═══════╩══════╝\n");
System.out.println("..Press Enter to return..");
sGet.nextLine();
}
/**
* Displays a table-like display of all Audio Tracks stored in Media Collection.
* Formats text to keep within the bounds of the table.
*/
private static void viewListAudioTracks()
{
ArrayList<AudioTrack> audioTracks = mediaCollection.getAudioTracks();
displayHeader();
String title = null;
int yearOfRelease = 0;
int rating = 0;
System.out.println("╔══════════════╦═══════════════╦══════╗");
System.out.println("║Title ║Year of Release║Rating║");
System.out.println("╠══════════════╩═══════╤═══════╬══════╣");
for (AudioTrack audioTrack : audioTracks)
{
title = audioTrack.getTitle();
yearOfRelease = audioTrack.getYearOfRelease();
rating = audioTrack.getRating();
if (title.length()>20)
{
System.out.format("║%.20s..│ %4d ║ %d/5 ║\n", title, yearOfRelease, rating);
}
else
{
System.out.format("║%-22s│ %4d ║ %d/5 ║\n", title, yearOfRelease, rating);
}