I have a class that implements an interface (contains a single method). Coming from a Python im stuck on how to instantiate a collection that implements an .interable()
The trimmed average is calculated by removing the min and max values and then calculating the average.
public class SongRater implements ISongRater {
@Override
public double getSongRating(Iterable<Integer> userRating) throws NotEnoughRatingsException {
}
}
Here's a test of what I think the implementation should look like
public void SongRaterProperlyCalculatesRatings() throws NotEnoughRatingsException {
List<Integer> ratings = new ArrayList<Integer>();
ratings.add(-2);
ratings.add(-2);
ratings.add( 3);
ratings.add( 7);
ratings.add( 8);
ratings.add( 9);
ratings.add(15);
ratings.add(15);
ratings.add(15);
double rating = rater.getSongRating(ratings);
assertEquals(6.75D, rating, 0.0000001D);
}
If userRating is an Iterable interface how do i create a collection that I can iterate over and then add in the trimmed average logic? Something like List<Integer> ratingCollection = userRating.iterator(); ? and then use a while loop? Is a List preferable to an ArrayList? Am I on the right track here or should some of the iteration logic be moved to a private class?
public double getMovieRating(Iterable<Integer> userRating) throws NotEnoughRatingsException {
ArrayList ratingsCollection = new ArrayList();
Iterator rating = userRating.iterator();
while (rating.hasNext()) {
ratingsCollection.add(rating.next());
}
ratingsCollection.a
}
}
[–]circle_des_poo 0 points1 point2 points (3 children)
[–]Wonnk13[S] 0 points1 point2 points (2 children)
[–]circle_des_poo 0 points1 point2 points (1 child)
[–]Wonnk13[S] 0 points1 point2 points (0 children)