Skip to content

Commit ffcdc6c

Browse files
committed
Week2. a public method named getAverageRatings
1 parent 977ad99 commit ffcdc6c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Week2/src/SecondRatings.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,24 @@ private Double getAverageByID(String id, Integer minimalRaters) {
8484
// If there are no ratings returns 0.0
8585
return result;
8686
}
87+
88+
/**
89+
* This method should find the average rating for every movie that has been rated by at least
90+
* minimalRaters raters.
91+
*
92+
* @param minimalRaters int the minimal number of raters supplying a rating
93+
* @return an ArrayList of all the Rating objects for movies that have at least the minimal number
94+
* of raters supplying a rating
95+
*/
96+
public ArrayList<Rating> getAverageRatings(int minimalRaters) {
97+
ArrayList<Rating> list = new ArrayList<>();
98+
for (Movie movie : myMovies) {
99+
String movieID = movie.getID();
100+
Double averageRating = getAverageByID(movieID, minimalRaters);
101+
if (averageRating != 0.0) {
102+
list.add(new Rating(movieID, averageRating));
103+
}
104+
}
105+
return list;
106+
}
87107
}

0 commit comments

Comments
 (0)