Java Reference
In-Depth Information
Code 7.1
continued
The SalesItem class
/**
* Return the number of customer comments for this item.
*/
public int getNumberOfComments()
{
return comments.size();
}
/**
* Add a comment to the comment list of this sales item. Return
* true if successful, false if the comment was rejected.
*
* The comment will be rejected if the same author has already
* left a comment or if the rating is invalid. Valid ratings are
* numbers between 1 and 5 (inclusive).
*/
public boolean addComment(String author, String text, int rating)
{
if (ratingInvalid(rating)) { // reject invalid ratings
return false ;
}
if (findCommentByAuthor(author) != null ) {
// reject multiple comments by same author
return false ;
}
comments.add( new Comment(author, text, rating));
return true ;
}
/**
* Remove the comment stored at the index given. If the index is
* invalid, do nothing.
*/
public void removeComment( int index)
{
if (index >=0 && index < comments.size()) { // index is valid
comments.remove(index);
}
}
/**
* Upvote the comment at 'index'. That is: count this comment as
* more helpful. If the index is invalid, do nothing.
*/
Search WWH ::




Custom Search