Skip to content

Commit e5d121c

Browse files
committed
Week4. getAverageByID
1 parent eea3556 commit e5d121c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Week4/src/FourthRatings.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.ArrayList;
2+
3+
/**
4+
* The week 4 class
5+
*
6+
* @author Stanislav Rakitov
7+
* @version 1.0
8+
*/
9+
public class FourthRatings {
10+
11+
private Double getAverageByID(String movieID, Integer minimalRaters) {
12+
ArrayList<Rater> myRaters = RaterDatabase.getRaters();
13+
long numOfRatings = myRaters.stream().filter(rater -> rater.hasRating(movieID)).count();
14+
15+
if (numOfRatings >= minimalRaters) {
16+
return myRaters.stream()
17+
.filter(rater -> rater.hasRating(movieID))
18+
.mapToDouble(rating -> rating.getRating(movieID))
19+
.average()
20+
.orElse(0.0);
21+
}
22+
return 0.0;
23+
}
24+
}

0 commit comments

Comments
 (0)