22import java .util .Collections ;
33
44public class MovieRunnerAverage {
5+ private final SecondRatings secondRatings ;
56
6- public MovieRunnerAverage () {}
7+ public MovieRunnerAverage () {
8+ secondRatings = new SecondRatings ("ratedmoviesfull.csv" , "ratings.csv" );
9+ }
710
8- public void printAverageRatings () {
9- SecondRatings secondRatings = new SecondRatings ("ratedmovies_short.csv" , "ratings_short.csv" );
10- System .out .printf (
11- "Total number of movies %d, total number of raters %d\n " ,
12- secondRatings .getMovieSize (), secondRatings .getRaterSize ());
11+ public void printAverageRatings (int minimalRatings ) {
12+ // SecondRatings secondRatings = new SecondRatings("ratedmovies_short.csv",
13+ // "ratings_short.csv");
14+ // System.out.printf(
15+ // "Total number of movies %d, total number of raters %d\n",
16+ // secondRatings.getMovieSize(), secondRatings.getRaterSize());
1317
1418 /*
1519 * In the MovieRunnerAverage class in the printAverageRatings method,
@@ -26,13 +30,22 @@ public void printAverageRatings() {
2630 * 8.25 Her
2731 * 9.0 The Godfather
2832 * */
29- ArrayList <Rating > ratedList = secondRatings .getAverageRatings (3 );
33+ ArrayList <Rating > ratedList = secondRatings .getAverageRatings (minimalRatings );
3034 Collections .sort (ratedList );
31- for (Rating ratedObj : ratedList ) {
32- double rating = ratedObj .getValue ();
33- String movieID = ratedObj .getItem ();
34- String movieTitle = secondRatings .getTitle (movieID );
35- System .out .println (rating + " " + movieTitle );
36- }
35+ System .out .printf ("Total movies with %d ratings is %d\n " , minimalRatings , ratedList .size ());
36+ System .out .printf (
37+ "The name of the movie that has the lowest rating is \" %s\" \n " ,
38+ secondRatings .getTitle (ratedList .get (0 ).getItem ()));
39+ // for (Rating ratedObj : ratedList) {
40+ // double rating = ratedObj.getValue();
41+ // String movieID = ratedObj.getItem();
42+ // String movieTitle = secondRatings.getTitle(movieID);
43+ // System.out.println(rating + " " + movieTitle);
44+ // }
45+ }
46+
47+ Double getAverageRatingOneMovie (String movieTitle ) {
48+ String movieID = secondRatings .getID (movieTitle );
49+ return secondRatings .getAverageByID (movieID , 1 );
3750 }
3851}
0 commit comments