-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewsFeed.java
59 lines (50 loc) · 1.25 KB
/
NewsFeed.java
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
52
53
54
55
56
57
58
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* A program Team Project
*
* <p>Purdue University -- CS18000 -- Spring 2024 -- Team Project-- </p>
*
* @author Purdue CS
* @version Mar 31, 2024
*/
public class NewsFeed {
private List<Post> postList;
private String owner;
public NewsFeed() {
this.postList = new ArrayList<>();
}
public void addPost(Post post) {
postList.add(post);
}
public void removePost(Post post) {
postList.remove(post);
}
public Post getPost(String title) {
for (Post post : postList) {
if (post.getTitle().equals(title)) {
return post;
}
}
return null;
}
public void viewNewsFeed() throws PostIncompleteException {
for (Post post : postList) {
System.out.println(post);
}
}
public String getOwner() {
return owner;
}
public String toString() {
StringBuilder newsFeed = new StringBuilder();
for (Post post : postList) {
newsFeed.append(post.toString()).append("\n");
}
return newsFeed.toString();
}
}