@@ -46,16 +46,20 @@ public void printAverageRatings(int minimalRatings) {
4646 printRatingsList (averageRatings );
4747 }
4848
49- private void printRatingsList (ArrayList <Rating > averageRatings ) {
50- averageRatings .stream ()
49+ private void printRatingsList (ArrayList <Rating > averageRatingList ) {
50+ System .out .printf ("Found %d movies%n" , averageRatingList .size ());
51+ averageRatingList .stream ()
5152 .sorted ()
5253 .forEach (
53- rating ->
54- System .out .printf (
55- "%-4s %s %s%n" ,
56- rating .getValue (),
57- MovieDatabase .getYear (rating .getItem ()),
58- MovieDatabase .getTitle (rating .getItem ())));
54+ rating -> {
55+ String movieID = rating .getItem ();
56+ System .out .printf ("%-4s %s%n" , rating .getValue (), MovieDatabase .getTitle (movieID ));
57+ System .out .println (" Year: " + MovieDatabase .getYear (movieID ));
58+ System .out .println (" Time: " + MovieDatabase .getMinutes (movieID ));
59+ System .out .println (" Genre(s): " + MovieDatabase .getGenres (movieID ));
60+ System .out .println (" Director(s): " + MovieDatabase .getDirector (movieID ));
61+ });
62+ System .out .println ("-------" );
5963 }
6064
6165 /**
@@ -65,12 +69,8 @@ private void printRatingsList(ArrayList<Rating> averageRatings) {
6569 * @param year int Year of produce
6670 */
6771 public void printAverageRatingsByYear (int minimalRatings , int year ) {
68- System .out .println ("number of raters " + thirdRatings .getRaterSize ());
69- System .out .println ("number of movies " + MovieDatabase .size ());
70- ArrayList <Rating > aveRating =
71- thirdRatings .getAverageRatingsByFilter (minimalRatings , new YearAfterFilter (year ));
72- System .out .printf ("found %d movies%n" , aveRating .size ());
73- printRatingsList (aveRating );
72+ printRatingsList (
73+ thirdRatings .getAverageRatingsByFilter (minimalRatings , new YearAfterFilter (year )));
7474 }
7575
7676 /**
@@ -80,20 +80,8 @@ public void printAverageRatingsByYear(int minimalRatings, int year) {
8080 * @param genre Genre
8181 */
8282 public void printAverageRatingsByGenre (int minimalRatings , String genre ) {
83- ArrayList <Rating > averageRatings =
84- thirdRatings .getAverageRatingsByFilter (minimalRatings , new GenreFilter (genre ));
85- System .out .printf ("found %d movies%n" , averageRatings .size ());
86- averageRatings .stream ()
87- .sorted ()
88- .forEach (
89- rating -> {
90- String movieID = rating .getItem ();
91- System .out .printf (
92- "%-4s %s%n %s%n" ,
93- rating .getValue (),
94- MovieDatabase .getTitle (movieID ),
95- MovieDatabase .getGenres (movieID ));
96- });
83+ printRatingsList (
84+ thirdRatings .getAverageRatingsByFilter (minimalRatings , new GenreFilter (genre )));
9785 }
9886
9987 /**
@@ -104,20 +92,19 @@ public void printAverageRatingsByGenre(int minimalRatings, String genre) {
10492 * @param maxMinutes Maximum length of movies in minutes
10593 */
10694 public void printAverageRatingsByMinutes (int minimalRatings , int minMinutes , int maxMinutes ) {
107- ArrayList < Rating > averageRatings =
95+ printRatingsList (
10896 thirdRatings .getAverageRatingsByFilter (
109- minimalRatings , new MinutesFilter (minMinutes , maxMinutes ));
110- System .out .printf ("found %d movies%n" , averageRatings .size ());
111- averageRatings .stream ()
112- .sorted ()
113- .forEach (
114- rating -> {
115- String movieID = rating .getItem ();
116- System .out .printf (
117- "%-4s Time: %-3d %s%n" ,
118- rating .getValue (),
119- MovieDatabase .getMinutes (movieID ),
120- MovieDatabase .getTitle (movieID ));
121- });
97+ minimalRatings , new MinutesFilter (minMinutes , maxMinutes )));
98+ }
99+
100+ /**
101+ * Print a list of movies and their average ratings sorted by time
102+ *
103+ * @param minimalRatings Minimal number of ratings
104+ * @param directors directors of the movies
105+ */
106+ public void printAverageRatingsByDirectors (int minimalRatings , String directors ) {
107+ printRatingsList (
108+ thirdRatings .getAverageRatingsByFilter (minimalRatings , new DirectorsFilter (directors )));
122109 }
123110}
0 commit comments