我的 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
}