-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathJavaTaskManager.java
130 lines (109 loc) · 3.87 KB
/
JavaTaskManager.java
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
118
119
120
121
122
123
124
125
126
127
128
129
130
import java.util.ArrayList;
import java.util.Scanner;
import java.time.LocalDate;
class Task {
private String description;
private LocalDate dueDate;
private boolean completed;
public Task(String description, LocalDate dueDate) {
this.description = description;
this.dueDate = dueDate;
this.completed = false;
}
public String getDescription() {
return description;
}
public LocalDate getDueDate() {
return dueDate;
}
public boolean isCompleted() {
return completed;
}
public void setCompleted(boolean completed) {
this.completed = completed;
}
}
public class TaskManager {
private static ArrayList<Task> tasks = new ArrayList<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice = 0;
while (choice != 4) {
displayMenu();
choice = scanner.nextInt();
switch (choice) {
case 1:
createTask(scanner);
break;
case 2:
viewTasks();
break;
case 3:
markAsCompleted(scanner);
break;
case 4:
System.out.println("Exiting the Task Manager. Goodbye!");
break;
default:
System.out.println("Invalid choice. Please choose a valid option.");
break;
}
checkReminders();
}
scanner.close();
}
private static void displayMenu() {
System.out.println("\nTask Manager Menu:");
System.out.println("1. Create a Task");
System.out.println("2. View Tasks");
System.out.println("3. Mark Task as Completed");
System.out.println("4. Exit");
System.out.print("Choose an option: ");
}
private static void createTask(Scanner scanner) {
scanner.nextLine();
System.out.print("Enter task description: ");
String description = scanner.nextLine();
System.out.print("Enter due date (YYYY-MM-DD): ");
String dateStr = scanner.next();
LocalDate dueDate = LocalDate.parse(dateStr);
Task newTask = new Task(description, dueDate);
tasks.add(newTask);
System.out.println("Task created successfully!");
}
private static void viewTasks() {
if (tasks.isEmpty()) {
System.out.println("No tasks available.");
} else {
System.out.println("Tasks:");
for (int i = 0; i < tasks.size(); i++) {
Task task = tasks.get(i);
System.out.println((i + 1) + ". " + task.getDescription() + " - Due: " + task.getDueDate() +
" - Completed: " + (task.isCompleted() ? "Yes" : "No"));
}
}
}
private static void markAsCompleted(Scanner scanner) {
viewTasks();
if (!tasks.isEmpty()) {
System.out.print("Enter the number of the task to mark as completed: ");
int taskNumber = scanner.nextInt();
if (taskNumber > 0 && taskNumber <= tasks.size()) {
Task task = tasks.get(taskNumber - 1);
task.setCompleted(true);
System.out.println("Task marked as completed: " + task.getDescription());
} else {
System.out.println("Invalid task number.");
}
}
}
private static void checkReminders() {
System.out.println("\nChecking for overdue tasks...");
LocalDate currentDate = LocalDate.now();
for (Task task : tasks) {
if (!task.isCompleted() && currentDate.isAfter(task.getDueDate())) {
System.out.println("Reminder: Task \"" + task.getDescription() + "\" is due!");
}
}
}
}