-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecondRatings.java
111 lines (90 loc) · 2.67 KB
/
SecondRatings.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import edu.duke.*;
import java.util.*;
import org.apache.commons.csv.*;
/**
* Write a description of SecondRatings here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SecondRatings {
private ArrayList<Movie> myMovies;
private ArrayList<Rater> myRaters;
public SecondRatings() {
// default constructor
this("ratedmoviesfull.csv", "ratings.csv");
}
public SecondRatings(String moviefile, String loadRaters){
//create a FirsrRatings object
FirstRatings fr = new FirstRatings();
// call the loadMovies and loadRaters
myMovies = fr.loadMovies(moviefile);
myRaters = fr.loadRaters(loadRaters);
}
public int getMovieSize(){
return myMovies.size();
}
public int getRaterSize(){
return myRaters.size();
}
private double getAverageByID(String id,int minimalRaters){
double average =0;
double total=0;
int countRaters= 0;
for(Rater rater:myRaters){
if(rater.hasRating(id)){
countRaters++;
total = total + rater.getRating(id);
}
}
if(countRaters >= minimalRaters){
average = total/countRaters;
}
return average;
}
public ArrayList<Rating> getAverageRatings(int minimalRaters){
ArrayList<Rating> avgRatingList = new ArrayList<Rating>();
for(Movie movie:myMovies){
//System.out.println("movie: " + movie);
String id = movie.getID();
//System.out.println("Get Movie ID: "+ id);
double avg = getAverageByID(id,minimalRaters);
//System.out.println("avg: " + avg);
if(avg>0.0){
Rating currRating = new Rating(id,avg);
avgRatingList.add(currRating);
}
}
return avgRatingList;
}
public String getTitle(String id){
String title= "";
for(Movie movie:myMovies){
if(movie.getID().equals(id)){
title = movie.getTitle();
break;
}
}
if(title == ""){
return "This id is Not Found";
}
else{
return id;
}
}
public String getID(String title){
String id ="";
for(Movie movie:myMovies){
if(movie.getTitle().equals(title)){
id = movie.getID();
break;
}
}
if(id ==""){
return "No SUCH TITLE";
}
else{
return id;
}
}
}