-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost.java
More file actions
50 lines (42 loc) · 1.31 KB
/
Post.java
File metadata and controls
50 lines (42 loc) · 1.31 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
package discussionboard;
public class Post {
// instance varibales
private String title;
private String content;
private User user;
// constructor to set the instance varibales
public Post(String postTitle, String postContent, User userInfo) {
// check for empty post title
if (postTitle == null || postTitle.trim().isEmpty()) {
throw new IllegalArgumentException("Post title cannot be empty");
}
// check for empty post conent
if(postContent == null || postContent.trim().isEmpty()){
throw new IllegalArgumentException("Post content cannot be empty");
}
title = postTitle;
content = postContent;
user = userInfo;
}
// getter for title
public String getTitle() {
return title;
}
// getter for content
public String getContent() {
return content;
}
// getter for username
public String getUserName() {
return user.getUserName();
}
// getter for user full name
public String getUserFullname() {
return user.getFullName();
}
// printing the post
public String toString() {
return "\nCreated By: " + user.getFullName() + "(@" + user.getUserName() + ")\n" + "Title: " + title + "\n"
+ content;
}
}