|
| 1 | +import java.util.ArrayList; |
| 2 | +import java.util.Collections; |
| 3 | + |
| 4 | +/** @author Stanislav Rakitov */ |
| 5 | +public class MovieRunnerSimilarRatings { |
| 6 | + |
| 7 | + /** |
| 8 | + * Print a list of movies and their average ratings sorted by averages |
| 9 | + * |
| 10 | + * @param minimalRatings int specified number of ratings |
| 11 | + */ |
| 12 | + public void printAverageRatings(int minimalRatings) { |
| 13 | + FourthRatings fourthRatings = new FourthRatings(); |
| 14 | + ArrayList<Rating> ratedList = fourthRatings.getAverageRatings(minimalRatings); |
| 15 | + |
| 16 | + Collections.sort(ratedList); |
| 17 | + // Print the number of raters after creating a ThirdsRating object. |
| 18 | + System.out.printf("Total movies with %d ratings is %d\n", minimalRatings, ratedList.size()); |
| 19 | + |
| 20 | + // Print the number of movies in the database. |
| 21 | + System.out.println("The number of movies in the database is " + MovieDatabase.size()); |
| 22 | + |
| 23 | + // You will call getAverageRatings with a minimal number of raters to return an ArrayList of |
| 24 | + // type Rating. |
| 25 | + |
| 26 | + ArrayList<Rating> averageRatings = fourthRatings.getAverageRatings(minimalRatings); |
| 27 | + |
| 28 | + // Print out how many movies with ratings are returned, |
| 29 | + // then sort them, and print out the rating and title of each movie |
| 30 | + System.out.printf( |
| 31 | + "How many movies with ratings %d are returned: %d%n", |
| 32 | + minimalRatings, averageRatings.size()); |
| 33 | + |
| 34 | + printRatingsList(averageRatings); |
| 35 | + } |
| 36 | + |
| 37 | + public void printAverageRatingsByYearAfterAndGenre(int minimalRatings, int year, String genre) { |
| 38 | + FourthRatings fourthRatings = new FourthRatings(); |
| 39 | + AllFilters filters = new AllFilters(); |
| 40 | + filters.addFilter(new GenreFilter(genre)); |
| 41 | + filters.addFilter(new YearAfterFilter(year)); |
| 42 | + System.out.println(fourthRatings.getAverageRatingsByFilter(minimalRatings, filters).size()); |
| 43 | + |
| 44 | + // System.out.printf( |
| 45 | + // "Print movie(s) with at least %d rating in \"%s\" genre produced after year" + " of %d |
| 46 | + // %n", |
| 47 | + // minimalRatings, genre, year); |
| 48 | + // printRatingsList(thirdRatings.getAverageRatingsByFilter(minimalRatings, filters)); |
| 49 | + } |
| 50 | + |
| 51 | + private void printRatingsList(ArrayList<Rating> averageRatingList) { |
| 52 | + System.out.printf("Found %d movie(s)%n", averageRatingList.size()); |
| 53 | + averageRatingList.stream() |
| 54 | + .sorted() |
| 55 | + .forEach( |
| 56 | + rating -> { |
| 57 | + String movieID = rating.getItem(); |
| 58 | + System.out.printf("%-4s %s%n", rating.getValue(), MovieDatabase.getTitle(movieID)); |
| 59 | + System.out.println(" Year: " + MovieDatabase.getYear(movieID)); |
| 60 | + System.out.println(" Time: " + MovieDatabase.getMinutes(movieID)); |
| 61 | + System.out.println(" Genre(s): " + MovieDatabase.getGenres(movieID)); |
| 62 | + System.out.println(" Director(s): " + MovieDatabase.getDirector(movieID)); |
| 63 | + }); |
| 64 | + System.out.println("-------"); |
| 65 | + } |
| 66 | +} |
0 commit comments