-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNewsFeed.java
More file actions
51 lines (47 loc) · 1.15 KB
/
NewsFeed.java
File metadata and controls
51 lines (47 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.ArrayList;
/**
* The NewsFeed class stores news posts for the news feed in a
* social network application.
*
* Display of the posts is currently simulated by printing the
* details to the terminal. (Later, this should display in a browser.)
*
* This version does not save the data to disk, and it does not
* provide any search or ordering functions.
*
* @author Michael Kölling and David J. Barnes
* @version 0.2
*/
public class NewsFeed
{
private ArrayList<Post> posts;
/**
* Construct an empty news feed.
*/
public NewsFeed()
{
posts = new ArrayList<>();
}
/**
* Add a post to the news feed.
*
* @param post The post to be added.
*/
public void addPost(Post post)
{
posts.add(post);
}
/**
* Show the news feed. Currently: print the news feed details
* to the terminal. (To do: replace this later with display
* in web browser.)
*/
public void show()
{
// display all posts
for(Post post : posts) {
post.display();
System.out.println(); // empty line between posts
}
}
}