33
44public class MovieRunnerWithFilters {
55
6+ private final ThirdRatings thirdRatings ;
7+
8+ public MovieRunnerWithFilters (String moviesFileName , String ratingsFileName ) {
9+ this .thirdRatings = new ThirdRatings (moviesFileName , ratingsFileName );
10+ }
11+
12+ public MovieRunnerWithFilters () {
13+ this ("ratedmovies_short.csv" , "ratings_short.csv" );
14+ }
15+
616 /**
717 * Print a list of movies and their average ratings sorted by averages
818 *
919 * @param minimalRatings int specified number of ratings
1020 */
11- public static void printAverageRatings (int minimalRatings ) {
12- ThirdRatings thirdRatings = new ThirdRatings ("ratings_short.csv" );
21+ public void printAverageRatings (int minimalRatings ) {
22+ // ThirdRatings thirdRatings = new ThirdRatings("ratedmovies_short.csv",
23+ // "ratings_short.csv");
1324 ArrayList <Rating > ratedList = thirdRatings .getAverageRatings (minimalRatings );
1425
1526 Collections .sort (ratedList );
@@ -31,23 +42,30 @@ public static void printAverageRatings(int minimalRatings) {
3142 // Print out how many movies with ratings are returned,
3243 // then sort them, and print out the rating and title of each movie
3344 System .out .printf (
34- "How many movies with ratings %d are returned: %d\ n " ,
45+ "How many movies with ratings %d are returned: %d% n" ,
3546 minimalRatings , averageRatings .size ());
3647
48+ printRatingsList (averageRatings );
49+ }
50+
51+ private void printRatingsList (ArrayList <Rating > averageRatings ) {
3752 averageRatings .stream ()
3853 .sorted ()
3954 .forEach (
4055 rating ->
4156 System .out .printf (
42- "%-4s %s%n" , rating .getValue (), MovieDatabase .getTitle (rating .getItem ())));
43- // System.out.printf(
44- // "The name of the movie that has the lowest rating is \"%s\"\n",
45- // thirdRatings.getTitle(ratedList.get(0).getItem()));
46- // for (Rating ratedObj : ratedList) {
47- // double rating = ratedObj.getValue();
48- // String movieID = ratedObj.getItem();
49- // String movieTitle = secondRatings.getTitle(movieID);
50- // System.out.println(rating + " " + movieTitle);
51- // }
57+ "%-4s %s %s%n" ,
58+ rating .getValue (),
59+ MovieDatabase .getYear (rating .getItem ()),
60+ MovieDatabase .getTitle (rating .getItem ())));
61+ }
62+
63+ public void printAverageRatingsByYear (int minimalRatings , int year ) {
64+ System .out .println ("number of raters " + thirdRatings .getRaterSize ());
65+ System .out .println ("number of movies " + MovieDatabase .size ());
66+ ArrayList <Rating > aveRating =
67+ thirdRatings .getAverageRatingsByFilter (minimalRatings , new YearAfterFilter (year ));
68+ System .out .printf ("found %d movies%n" , aveRating .size ());
69+ printRatingsList (aveRating );
5270 }
5371}
0 commit comments