Java Reference
In-Depth Information
Code 7.1
continued
The
SalesItem
class
public
void
upvoteComment(
int
index)
{
if
(index >=0 && index < comments.size()) {
// index is valid
comments.get(index).upvote();
}
}
/**
* Downvote the comment at 'index'. That is: count this comment as
* less helpful. If the index is invalid, do nothing.
*/
public
void
downvoteComment(
int
index)
{
if
(index >=0 && index < comments.size()) {
// index is valid
comments.get(index).downvote();
}
}
/**
* Show all comments on screen. (Currently, for testing purposes:
* print to the terminal. Modify later for web display.)
*/
public
void
showInfo()
{
System.out.println(
"*** "
+ name +
" ***"
);
System.out.println(
"Price: "
+ priceString(price));
System.out.println();
System.out.println(
"Customer comments:"
);
for
(Comment comment : comments) {
System.out.println(
"-----------------------------------"
);
System.out.println(comment.getFullDetails());
}
System.out.println();
System.out.println(
"====================================="
);
}
/**
* Return the most helpful comment. The most useful comment is the
* one with the highest vote balance. If there are multiple
* comments with equal highest balance, return any one of them.
*/
public
Comment findMostHelpfulComment()
{
Iterator<Comment> it = comments.iterator();
Comment best = it.next();
Search WWH ::
Custom Search