Java Reference
In-Depth Information
Code 8.2
continued
Source code of the
PhotoPost class
private String caption; // a one-line image caption
private long timestamp;
private int likes;
private ArrayList<String> comments;
/**
* Constructor for objects of class PhotoPost.
*
* @param author The username of the author of this post.
* @param filename The filename of the image in this post.
* @param caption A caption for the image.
*/
public PhotoPost(String author, String filename, String caption)
{
username = author;
this .filename = filename;
this .caption = caption;
timestamp = System.currentTimeMillis();
likes = 0;
comments = new ArrayList<String>();
}
/**
* Record one more 'Like' indication from a user.
*/
public void like()
{
likes++;
}
/**
* Record that a user has withdrawn his/her 'Like' vote.
*/
public void unlike()
{
if (likes > 0) {
likes--;
}
}
/**
* Add a comment to this post.
*
* @param text The new comment to add.
*/
Search WWH ::




Custom Search