-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManager.java
More file actions
112 lines (89 loc) · 3.41 KB
/
Copy pathTaskManager.java
File metadata and controls
112 lines (89 loc) · 3.41 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
import java.util.*;
import java.time.LocalDateTime;
public class TaskManager {
ArrayList<Task> tasks;
StorageManager storageManager;
public void addTask(String description) {
int maxId = 0;
for(int i=0; i<tasks.size(); i++){
if(tasks.get(i).id>maxId) maxId = tasks.get(i).id;
}
int newId = maxId+1;
Task newTask = new Task();
newTask.id=newId;
newTask.description=description;
newTask.status=Status.TODO;
newTask.createdAt=LocalDateTime.now().toString();
newTask.updatedAt=LocalDateTime.now().toString();
tasks.add(newTask);
storageManager.save(tasks);
}
public void listTasks(){
if(tasks.size()==0){
System.out.println("No tasks found.");
return;
}
for(int i=0; i<tasks.size(); i++){
System.out.println("ID: "+tasks.get(i).id);
System.out.println("Description: "+tasks.get(i).description);
System.out.println("Status: "+tasks.get(i).status);
System.out.println("CreatedAt: "+tasks.get(i).createdAt);
System.out.println("UpdatedAt: "+tasks.get(i).updatedAt);
System.out.println();
}
}
public void listTasks(String filter){
try{
Status filterStatus = Status.valueOf(filter.toUpperCase().replace("-","_"));
for(int i=0; i<tasks.size(); i++){
if(tasks.get(i).status==filterStatus){
System.out.println("ID: "+tasks.get(i).id);
System.out.println("Description: "+tasks.get(i).description);
System.out.println("Status: "+tasks.get(i).status);
System.out.println("CreatedAt: "+tasks.get(i).createdAt);
System.out.println("UpdatedAt: "+tasks.get(i).updatedAt);
System.out.println();
}
}
}catch(IllegalArgumentException e){
System.out.println("Invalid status. Use: todo, in-progress, done");
}
}
public void deleteTask(int id){
for(int i=0; i<tasks.size(); i++){
if(tasks.get(i).id == id){
tasks.remove(i);
storageManager.save(tasks);
return;
}
}
System.out.println("Task not found.");
}
public void updateTask(int id, String newDescription){
for(int i=0; i<tasks.size(); i++){
if(tasks.get(i).id == id){
tasks.get(i).description = newDescription;
tasks.get(i).updatedAt = LocalDateTime.now().toString();
storageManager.save(tasks);
return;
}
}
System.out.println("Task not found.");
}
public void markStatus(String status, int id){
for(int i=0; i<tasks.size(); i++){
if(tasks.get(i).id==id){
try{
tasks.get(i).status = Status.valueOf(status.toUpperCase().replace("-","_"));
tasks.get(i).updatedAt = LocalDateTime.now().toString();
storageManager.save(tasks);
return;
}catch(IllegalArgumentException e){
System.out.println("Invalid status. Use: todo, in-progress, done");
return;
}
}
}
System.out.println("Task not found.");
}
}