-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieRunnerAverage.java
71 lines (50 loc) · 2.12 KB
/
MovieRunnerAverage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import edu.duke.*;
import java.util.*;
import org.apache.commons.csv.*;
/**
* Write a description of MovieRunnerAverage here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MovieRunnerAverage {
public void printAverageRatings(){
int minimalRaters =50;
//create secondRatings object
String moviesFile = "data/ratedmoviesfull.csv";
String ratingsFile = "data/ratings.csv";
SecondRatings sr = new SecondRatings(moviesFile,ratingsFile);
// print the number of movies and the number of raters
System.out.println("Number of rated movie: "+ sr.getMovieSize());
System.out.println("Number of raters: "+ sr.getRaterSize());
ArrayList<Rating> avgRatingList = sr.getAverageRatings(minimalRaters);
Collections.sort(avgRatingList);
for(Rating r:avgRatingList){
System.out.println(r.getValue()+ " : " + sr.getTitle(r.getItem()));
}
System.out.println("avgRatingList size " + avgRatingList.size());
}
public void getAverageRatingOneMovie(){
int minimalRaters=20;
// String title = "The Maze Runner";
String title = "Vacation";
String moviesFile = "data/ratedmoviesfull.csv";
String ratingsFile = "data/ratings.csv";
// create a SecondRatings object
SecondRatings sr = new SecondRatings(moviesFile,ratingsFile);
String id = sr.getID(title);
ArrayList<Rating> avgRatingList = sr.getAverageRatings(minimalRaters);
// System.out.println("avgRatingList: "+ avgRatingList);
for(Rating rating:avgRatingList){
if(rating.getItem().equals(id)){
System.out.println("Average rating for '" + title + "' is: " + rating.getValue());
}
}
System.out.println("There are " + avgRatingList.size() + " movies that has more than "+ minimalRaters + " minimal raters");
}
// public static void main(String[] args) {
// MovieRunnerAverage ref = new MovieRunnerAverage();
// ref.printAverageRatings();
// ref.getAverageRatingOneMovie();
// }
}