-
Notifications
You must be signed in to change notification settings - Fork 0
/
Post.java
139 lines (109 loc) · 3.74 KB
/
Post.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
/**
* Project 5 -- Post
*
* This class represents each post made by a student
* and has attributes of a post set as a field
*
* @author Yuvika Khurana, lab sec 023
*
* @version May 2, 2022
*/
public class Post implements Serializable {
String courseName; // Name of the course under which post is made
DiscussionTopic discussionTopic; // The Discussion Topic object of the discussion forum under which post is made
String post; // The Post Content
ArrayList<Reply> reply; // An ArrayList of replies / comments made on the post
Student student; // The Student who made the post
String timeStamp; // The timestamp for recording the time when the post is made
double grade; // The grade received on the post
//Post Constructor
public Post(String courseName, DiscussionTopic discussionTopic, String post,
ArrayList<Reply> reply, Student student) {
this.courseName = courseName;
this.discussionTopic = discussionTopic;
this.post = post;
this.reply = reply;
this.student = student;
this.grade = -1; // Grade initialised to -1
Timestamp ts = new Timestamp(System.currentTimeMillis());
this.timeStamp = ts.toString();
}
//Getters and Setters for each field
public double getGrade() {
return grade;
}
public void setGrade(double grade) {
this.grade = grade;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public DiscussionTopic getDiscussionTopic() {
return discussionTopic;
}
public void setDiscussionTopic(DiscussionTopic discussionTopic) {
this.discussionTopic = discussionTopic;
}
public String getPost() {
return post;
}
public void setPost(String post) {
this.post = post;
}
public ArrayList<Reply> getReply() {
return reply;
}
public void setReply(ArrayList<Reply> reply) {
this.reply = reply;
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
@Override
public String toString() {
String postString = courseName + "~";
if (discussionTopic != null) {
postString += discussionTopic.getTopic() + "~" + discussionTopic.getTimeStamp();
} else {
postString += "null";
}
if (post != null) {
postString += "~" + post;
} else {
postString += "~" + "null";
}
postString += "~" + reply.size();
for (int i = 0; i < reply.size(); i++) {
postString += "~" + reply.get(i).getResponse();
postString += "~" + reply.get(i).getPerson().getName();
postString += "~" + reply.get(i).getPerson().getUsername();
postString += "~" + reply.get(i).getPerson().getPassword();
postString += "~" + reply.get(i).getTimeStamp();
}
if (student != null) {
postString += "~" + student.getName();
postString += "~" + student.getUsername();
postString += "~" + student.getPassword();
} else {
postString += "~" + "null";
}
postString += "~" + timeStamp;
postString += "~" + grade;
return postString;
}
}