-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodo.java
More file actions
100 lines (77 loc) · 3.1 KB
/
Copy pathTodo.java
File metadata and controls
100 lines (77 loc) · 3.1 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
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
class ReminderTask extends TimerTask {
private Task task;
public ReminderTask(Task task) {
this.task = task;
}
@Override
public void run() {
System.out.println("Reminder: Task '" + task.getDescription() + "' is due in 5 minutes!");
}
}
public class Todo {
private ArrayList<Category> categories;
public Todo() {
categories = new ArrayList<>();
}
public void addCategory(String categoryName) {
Category category = new Category(categoryName);
categories.add(category);
}
public void addTaskToCategory(Task task, Category category) {
category.addTask(task);
setupReminderTimer(task);
}
public void removeTaskFromCategory(int taskIndex, Category category) {
category.removeTask(taskIndex);
}
public void setupReminderTimer(Task task) {
int minutes = task.getMinutes();
Calendar dueTime = Calendar.getInstance();
dueTime.add(Calendar.MINUTE, minutes);
Calendar reminderTime = (Calendar) dueTime.clone();
reminderTime.add(Calendar.MINUTE, -5);
Timer timer = new Timer();
timer.schedule(new ReminderTask(task), reminderTime.getTime());
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Todo todo = new Todo();
boolean addCategory = true;
while (addCategory) {
System.out.print("Enter a category name: ");
String categoryName = scanner.nextLine();
todo.addCategory(categoryName);
System.out.print("How many tasks do you want to add? ");
int numTasks = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < numTasks; i++) {
System.out.print("Task " + i + ":\n");
String taskDescription = scanner.nextLine();
if (!taskDescription.isEmpty()) {
System.out.print("Enter the time (in minutes) this task is due: ");
int minutes = Integer.parseInt(scanner.nextLine());
Task task = new Task(taskDescription, minutes);
todo.addTaskToCategory(task, todo.categories.get(todo.categories.size() - 1));
}
}
System.out.print("Do you want to add another category? (yes/no) ");
String addAnotherCategory = scanner.nextLine();
addCategory = addAnotherCategory.equalsIgnoreCase("yes");
}
System.out.println("\nYour Tasks:\n");
for (Category category : todo.categories) {
System.out.println("Category: " + category.getName());
ArrayList<Task> taskList = category.getTaskList();
for (int i = 0; i < taskList.size(); i++) {
Task task = taskList.get(i);
System.out.println((i + 1) + ". " + task.getDescription() + " - " + task.getTimeString());
}
System.out.println();
}
scanner.close();
}
}