Repository navigation
Expand file tree
/
Copy pathTaskManager.java
More file actions
112 lines (91 loc) · 3.36 KB
/
Copy pathTaskManager.java
File metadata and controls
112 lines (91 loc) · 3.36 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.ArrayList;
import java.util.List;
import java.util.Scanner;
public class TaskManager {
private List<Task> tasks = new ArrayList<>();
private Scanner scanner = new Scanner(System.in);
public void addTask() {
System.out.print("Enter Task Title: ");
String title = scanner.nextLine();
System.out.print("Enter Task Description: ");
String description = scanner.nextLine();
System.out.print("Enter Priority (LOW, MEDIUM, HIGH): ");
String priority = scanner.nextLine().toUpperCase();
System.out.print("Enter Deadline (yyyy-mm-dd): ");
String deadline = scanner.nextLine();
Task task = new Task(title, description, priority, deadline);
tasks.add(task);
System.out.println("Task added successfully!");
}
public void editTask() {
System.out.print("Enter Task Title to Edit: ");
String title = scanner.nextLine();
Task task = findTask(title);
if (task != null) {
System.out.print("Enter new Title: ");
task.setTitle(scanner.nextLine());
System.out.print("Enter new Description: ");
task.setDescription(scanner.nextLine());
System.out.print("Enter new Priority (LOW, MEDIUM, HIGH): ");
task.setPriority(scanner.nextLine().toUpperCase());
System.out.print("Enter new Deadline (yyyy-mm-dd): ");
task.setDeadline(scanner.nextLine());
System.out.println("Task updated successfully!");
} else {
System.out.println("Task not found.");
}
}
public void deleteTask() {
System.out.print("Enter Task Title to Delete: ");
String title = scanner.nextLine();
Task task = findTask(title);
if (task != null) {
tasks.remove(task);
System.out.println("Task deleted successfully!");
} else {
System.out.println("Task not found.");
}
}
public void markTaskCompleted() {
System.out.print("Enter Task Title to Mark as Completed: ");
String title = scanner.nextLine();
Task task = findTask(title);
if (task != null) {
task.setCompleted(true);
System.out.println("Task marked as completed!");
} else {
System.out.println("Task not found.");
}
}
public void trackTaskProgress() {
System.out.print("Enter Task Title to Track Progress: ");
String title = scanner.nextLine();
Task task = findTask(title);
if (task != null) {
System.out.print("Enter progress increment (10, 20, etc.): ");
int increment = scanner.nextInt();
scanner.nextLine(); // consume newline
task.showProgress(increment);
} else {
System.out.println("Task not found.");
}
}
public void viewTasks() {
if (tasks.isEmpty()) {
System.out.println("No tasks available.");
return;
}
for (Task task : tasks) {
System.out.println(task);
System.out.println("------------------------------");
}
}
private Task findTask(String title) {
for (Task task : tasks) {
if (task.getTitle().equalsIgnoreCase(title)) {
return task;
}
}
return null;
}
}