|
| 1 | +import java.util.ArrayList; |
| 2 | +import java.util.Collections; |
| 3 | + |
| 4 | +public class MovieRunnerWithFilters { |
| 5 | + |
| 6 | + /** |
| 7 | + * Print a list of movies and their average ratings sorted by averages |
| 8 | + * |
| 9 | + * @param minimalRatings int specified number of ratings |
| 10 | + */ |
| 11 | + public static void printAverageRatings(int minimalRatings) { |
| 12 | + ThirdRatings thirdRatings = new ThirdRatings("ratings_short.csv"); |
| 13 | + ArrayList<Rating> ratedList = thirdRatings.getAverageRatings(minimalRatings); |
| 14 | + |
| 15 | + Collections.sort(ratedList); |
| 16 | + // Print the number of raters after creating a ThirdsRating object. |
| 17 | + System.out.printf("Total movies with %d ratings is %d\n", minimalRatings, ratedList.size()); |
| 18 | + |
| 19 | + // You’ll call the MovieDatabase initialize method with the moviefile to set up the movie |
| 20 | + // database. |
| 21 | + MovieDatabase.initialize("ratedmoviesfull.csv"); |
| 22 | + |
| 23 | + // Print the number of movies in the database. |
| 24 | + System.out.println("The number of movies in the database is " + MovieDatabase.size()); |
| 25 | + |
| 26 | + // You will call getAverageRatings with a minimal number of raters to return an ArrayList of |
| 27 | + // type Rating. |
| 28 | + |
| 29 | + ArrayList<Rating> averageRatings = thirdRatings.getAverageRatings(minimalRatings); |
| 30 | + |
| 31 | + // Print out how many movies with ratings are returned, |
| 32 | + // then sort them, and print out the rating and title of each movie |
| 33 | + System.out.printf( |
| 34 | + "How many movies with ratings %d are returned: %d\n", |
| 35 | + minimalRatings, averageRatings.size()); |
| 36 | + |
| 37 | + averageRatings.stream() |
| 38 | + .sorted() |
| 39 | + .forEach( |
| 40 | + rating -> |
| 41 | + 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 | + // } |
| 52 | + } |
| 53 | +} |
0 commit comments