-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManager.java
More file actions
77 lines (69 loc) · 2.22 KB
/
Copy pathTaskManager.java
File metadata and controls
77 lines (69 loc) · 2.22 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
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class TaskManager {
private static TaskManager instance;
private List<Task> taskList = new ArrayList<>();
private TaskManager(){
}
public static TaskManager getInstance(){
if(instance == null){
instance = new TaskManager();
}
return instance;
}
public void addTask(Task task){
taskList.add(task);
System.out.println("Task added successfully! \n");
}
// view all tasks
public void viewAllTasks(){
if(taskList.isEmpty()){
System.out.println("No tasks found. \n");
return;
}
for(Task task : taskList){
String status = task.getStatus() ? "done":"Pending";
System.out.println(task.getTitle()+"--"+task.getDescription()+". Status: "+status);
}
System.out.println();
}
// view tasks by tag
public void viewTasksByTag(String tag){
boolean found = false;
for (Task task: taskList) {
String status = task.getStatus() ? "done":"Pending";
if (task.getTag().equalsIgnoreCase(tag)) {
System.out.println(task.getTitle()+"--"+task.getDescription()+". Status: "+status);
found = true;
}
}
if(!found){
System.out.println("Task not found with this tag: "+tag);
}
}
// Mark As Done
public void markAsDone(String title){
for(Task task: taskList){
if(task.getTitle().equalsIgnoreCase(title)){
task.setStatus(true);
System.out.println("This task marked as Done.");
return;
}
}
System.out.println("Task not found.\n");
}
// Delete task
public void deleteTask(String title){
Iterator<Task> iterator = taskList.iterator();
while (iterator.hasNext()) {
Task task = iterator.next();
if(task.getTitle().equalsIgnoreCase(title)){
iterator.remove();
System.out.println("Task deleted successfully.");
return;
}
}
System.out.println("Task not found.\n");
}
}