2
2
import java .util .Collections ;
3
3
4
4
public class MovieRunnerAverage {
5
+ private final SecondRatings secondRatings ;
5
6
6
- public MovieRunnerAverage () {}
7
+ public MovieRunnerAverage () {
8
+ secondRatings = new SecondRatings ("ratedmoviesfull.csv" , "ratings.csv" );
9
+ }
7
10
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());
13
17
14
18
/*
15
19
* In the MovieRunnerAverage class in the printAverageRatings method,
@@ -26,13 +30,22 @@ public void printAverageRatings() {
26
30
* 8.25 Her
27
31
* 9.0 The Godfather
28
32
* */
29
- ArrayList <Rating > ratedList = secondRatings .getAverageRatings (3 );
33
+ ArrayList <Rating > ratedList = secondRatings .getAverageRatings (minimalRatings );
30
34
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 );
37
50
}
38
51
}
0 commit comments