-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task.java
60 lines (50 loc) · 1.84 KB
/
Task.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
package model;
import org.json.JSONObject;
import persistence.Writable;
// Represents a task with a task description and a status of whether it is completed or not
public class Task implements Writable {
private String taskDescription; //description of the to-do task
private boolean isCompleted; // status of task, whether it is completed or not
// EFFECTS: to-do list has a description and is not completed
public Task(String taskDescription) {
this.taskDescription = taskDescription;
isCompleted = false;
}
// EFFECTS: returns the task description
public String getTaskDescription() {
return taskDescription;
}
// EFFECTS: returns true if task is completed, false otherwise
public boolean isCompleted() {
return isCompleted;
}
// MODIFIES: this
// EFFECTS: marks task as complete
public void markAsComplete() {
EventLog.getInstance().logEvent(new Event("A task was marked as complete"));
isCompleted = true;
}
// MODIFIES: this
// EFFECTS: marks task as incomplete
public void markAsIncomplete() {
EventLog.getInstance().logEvent(new Event("A task was marked as incomplete"));
isCompleted = false;
}
// EFFECTS: returns a string of whether or not a task is complete
public String taskStatusAsString() {
if (this.isCompleted) {
return "[COMPLETED]";
} else {
return "[NOT COMPLETED]";
}
}
// This method references code from JsonSerializationDemo
// https://github.students.cs.ubc.ca/CPSC210/JsonSerializationDemo.git
@Override
public JSONObject toJson() {
JSONObject json = new JSONObject();
json.put("task description", taskDescription);
json.put("completion status", isCompleted);
return json;
}
}