Java Reference
In-Depth Information
Code 7.1
continued
The SalesItem class
while (it.hasNext()) {
Comment current = it.next();
if (current.getVoteCount() > best.getVoteCount()) {
best = current;
}
}
return best;
}
/**
* Check whether the given rating is invalid. Return true if it is
* invalid. Valid ratings are in the range [1..5].
*/
private boolean ratingInvalid( int rating)
{
return rating < 0 || rating > 5;
}
/**
* Find the comment by the author with the given name.
*
* @return The comment if it exists, null if it doesn'>t.
*/
private Comment findCommentByAuthor(String author)
{
for (Comment comment : comments) {
if (comment.getAuthor().equals(author)) {
return comment;
}
}
return null ;
}
/**
* For a price given as an int, return a readable String
* representing the same price. The price is given in whole cents.
* For example for price==12345, the following String
* is returned: $123.45
*/
private String priceString( int price)
{
int dollars = price / 100;
int cents = price — (dollars*100);
Search WWH ::




Custom Search