Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Utilities{ /** * step 3.1 * * Computes the average of any number of

ID: 3592801 • Letter: P

Question

public class Utilities{

/**

* step 3.1

*

* Computes the average of any number of ratings

*

* @param ratings A list of integer ratings in the range of 1-5 inclusive

* @return The average of all ratings in the list as a double

*/

public double averageRating(ArrayList<Integer> ratings){

return 0.0; //replace 0.0

}

/**

* step 3.2

*

* Computes the Bayesian average of any number of reviews

*

* Hint: You can call your method from 3.1 to compute the standard average of the ratings then

* call the Bayesian average method from part 1 to compute the Bayesian average.

*

* @param ratings A list of integer ratings in the range of 1-5 inclusive

* @param numberOfExtraRatings The number of extra ratings to be added to the average

* @param extraRatingValue The value of the extra ratings

* @return The Bayesian average of all ratings in the list as a double

*/

public double bayesianAverage(ArrayList<Integer> ratings, int numberOfExtraRatings, double extraRatingValue){

return 0.0; //replace 0.0

}

Explanation / Answer

pretend_upvotes = 4 pretend_downvotes = 10 def score(item_upvotes, item_downvotes): upvotes = item_upvotes + pretend_upvotes downvotes = item_downvotes + pretend_downvotes return upvotes / float(upvotes + downvotes) def score(item_votes): votes = [iv+pv for (iv,pv) in zip(item_votes,pretend_votes)] return sum(v*u for (v,u) in zip(votes,utilities))/float(sum(votes)) for i in 0..5: votes[i] = item_votes[i] + pretend_votes[i] score = sum(utilities[i] * votes[i] for i in 0..5) / sum(votes[i] for i in 0..5) pretend_votes = [2, 2, 2, 2, 2, 2]