-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.java
More file actions
42 lines (35 loc) · 1.33 KB
/
Task.java
File metadata and controls
42 lines (35 loc) · 1.33 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
import java.io.Serializable;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Task implements Serializable, Comparable<Task> {
private String description;
private boolean isDone;
private LocalDate dueDate;
private Priority priority;
public enum Priority { LOW, MEDIUM, HIGH }
public Task(String description, LocalDate dueDate, Priority priority) {
this.description = description;
this.isDone = false;
this.dueDate = dueDate;
this.priority = priority;
}
public String getDescription() { return description; }
public boolean isDone() { return isDone; }
public LocalDate getDueDate() { return dueDate; }
public Priority getPriority() { return priority; }
public void markAsDone() { this.isDone = true; }
@Override
public String toString() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return (isDone ? "[done] " : "[ ] ") + description +
" | Due: " + dueDate.format(formatter) +
" | Priority: " + priority;
}
@Override
public int compareTo(Task other) {
if (this.priority != other.priority) {
return other.priority.ordinal() - this.priority.ordinal();
}
return this.dueDate.compareTo(other.dueDate);
}
}