-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDo.java
More file actions
117 lines (94 loc) · 3.63 KB
/
ToDo.java
File metadata and controls
117 lines (94 loc) · 3.63 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
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
public class ToDo {
// ===========================================================================
// FIELDS
// ===========================================================================
private static int taskCount = 0; // To keep track how many tasks are being added
private int ID; // ID of the task
private String taskDesc; // Task Name
private boolean isDone; // Boolean to keep track of which task is done and which is not
private java.sql.Date dateAdded; // Date when the task was added
private String category; // Category of the task
// ===========================================================================
// CONSTRUCTOR
// ===========================================================================
// First Constructor which takes task name and category as parameters
ToDo(String desc, String category) {
// Initialize our fields
this.ID = ++taskCount; // Increment ID every time a task is added ( To have an unique ID )
this.taskDesc = desc; // Setting task name
this.isDone = false; // Setting the task not done initially
this.dateAdded = new java.sql.Date(new java.util.Date().getTime()); // Setting date provided by current date from Java library
// If category is null set it to "N/A"( Not Available ) else, set the category
if (category == null) {
this.category = "N/A";
} else {
this.category = category;
}
}
// Second Constructor which takes ID, task name and Category as parameters
ToDo(int ID, String desc, String category) {
// Initialize Fields
this.ID = ID; // Setting the ID got from parameter
this.taskDesc = desc; // Setting task name
this.isDone = false; // Setting the task not done initially
this.dateAdded = new java.sql.Date(new java.util.Date().getTime()); // Setting date provided by current date form Java library
// If category is null set it to "N/A"( Not Available ) else, set the category
if (category == null) {
this.category = "N/A";
} else {
this.category = category;
}
}
// ===========================================================================
// METHODS
// ===========================================================================
// GETTERS
// ---------------------------------------------------------------------------
// Getting ID
public int getID() {
return this.ID;
}
// Getting Task name
public String getTask() {
return this.taskDesc;
}
// Getting if the task is done or not done
public boolean isTaskDone() {
return this.isDone;
}
// Getting the add when the task was added
public java.sql.Date getDateAdded() {
return this.dateAdded;
}
// Getting the category of the task
public String getCategory() {
return this.category;
}
// ---------------------------------------------------------------------------
// SETTERS
// ---------------------------------------------------------------------------
// Editing the task name
public void editTask(String newDesc) {
this.taskDesc = newDesc;
}
// Marking the task done
public void markDone() {
this.isDone = !this.isDone;
}
// ---------------------------------------------------------------------------
// OTHER METHODS
// ---------------------------------------------------------------------------
// Set the emoji on console depending if the task is done or not
private String doneEmoji() {
if (this.isTaskDone()) {
return "[✔]";
}
return "[ ]";
}
// Conversion of Todo to String ( For Console Control )
@Override
public String toString() {
return String.format("%3s\t%-15s\t%-15s\t%-10s\t%10s", this.getID(), this.getTask(), this.getCategory(),
this.doneEmoji(), this.getDateAdded());
}
}