-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTo_Do.java
More file actions
48 lines (47 loc) · 1.89 KB
/
To_Do.java
File metadata and controls
48 lines (47 loc) · 1.89 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
import java.util.*;
public class To_Do {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<String> toDoList = new ArrayList<>();
while (true) {
System.out.println("To-Do List Application");
System.out.println("1. Add Task");
System.out.println("2. View Tasks");
System.out.println("3. Remove Task");
System.out.println("4. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.print("Enter task to add: ");
String taskToAdd = scanner.nextLine();
toDoList.add(taskToAdd);
System.out.println("Task added.");
break;
case 2:
System.out.println("Your Tasks:");
for (int i = 0; i < toDoList.size(); i++) {
System.out.println((i + 1) + ". " + toDoList.get(i));
}
break;
case 3:
System.out.print("Enter task number to remove: ");
int taskNumber = scanner.nextInt();
if (taskNumber > 0 && taskNumber <= toDoList.size()) {
toDoList.remove(taskNumber - 1);
System.out.println("Task removed.");
} else {
System.out.println("Invalid task number.");
}
break;
case 4:
System.out.println("Exiting application.");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}