Repository navigation
Expand file tree
/
Copy pathSecondRatings.java
More file actions
85 lines (82 loc) · 2.06 KB
/
Copy pathSecondRatings.java
File metadata and controls
85 lines (82 loc) · 2.06 KB
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
/**
* Write a description of SecondRatings here.
*
* @author (your name)
* Date : January 6th, 2025
*/
import java.util.*;
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 ratingsfile)
{
FirstRatings fr = new FirstRatings();
myMovies = fr.loadMovies(moviefile);
myRaters = fr.loadRaters(ratingsfile);
}
public int getMovieSize()
{
return myMovies.size();
}
public int getRaterSize()
{
return myRaters.size();
}
private double getAverageByID(String movieID, int minimalRaters)
{
double avg = 0.0;
int cnt = 0;
for(Rater rater : myRaters)
{
double rating = rater.getRating(movieID);
if(rating != -1)
{
avg = avg + rater.getRating(movieID);
cnt++;
}
}
if(cnt >= minimalRaters) return avg/cnt;
return 0.0;
}
public ArrayList<Rating> getAverageRatings(int minimalRaters)
{
ArrayList<Rating> ans = new ArrayList<Rating>();
for(Movie movie: myMovies)
{
double avg = getAverageByID(movie.getID(), minimalRaters);
if(avg != 0.0)
{
Rating a = new Rating(movie.getID(), avg);
ans.add(a);
}
}
return ans;
}
public String getTitle(String id)
{
for(Movie movie: myMovies)
{
if(movie.getID().compareTo(id) == 0)
{
return movie.getTitle();
}
}
return "This movie is not available";
}
public String getID(String title)
{
for(Movie movie : myMovies)
{
if(movie.getTitle().compareTo(title) == 0)
{
return movie.getID();
}
}
return "NO SUCH TITLE";
}
}