我的Hashmap 包含一个关键, 即客户名, 值是被评分的书的评级。 我必须计算给定的书名的平均评级 。
我如何访问哈马普的所有值( 评分)? 是否有方法做到这一点?
这是我的代码之一:
/**
* calculate the average rating by all customers for a named book
* only count positive or negative ratings, not 0 (unrated)
* if the booktitle is not found or their are no ratings then
* return NO_AVERAGE
* @param booktitle String to be rated
* @return double the average of all ratings for this book
*/
public double averageRating(String booktitle)
{
numberOfRatingsPerCustomer/total
}