-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1_To_Do_List.java
More file actions
75 lines (66 loc) · 2.83 KB
/
P1_To_Do_List.java
File metadata and controls
75 lines (66 loc) · 2.83 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
import java.util.ArrayList;
import java.util.Scanner;
public class P1_To_Do_List{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> tasks = new ArrayList<>();
int choice;
do {
System.out.println("\n===== 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. Update Task");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.print("Enter task: ");
String task = scanner.nextLine();
tasks.add(task);
System.out.println("Task added successfully!");
break;
case 2:
System.out.println("\nYour To-Do List:");
if (tasks.isEmpty()) {
System.out.println("No tasks found!");
} else {
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ". " + tasks.get(i));
}
}
break;
case 3:
System.out.print("Enter task number to remove: ");
int removeIndex = scanner.nextInt() - 1;
if (removeIndex >= 0 && removeIndex < tasks.size()) {
tasks.remove(removeIndex);
System.out.println("Task removed successfully!");
} else {
System.out.println("Invalid task number!");
}
break;
case 4:
System.out.print("Enter task number to update: ");
int updateIndex = scanner.nextInt() - 1;
scanner.nextLine();
if (updateIndex >= 0 && updateIndex < tasks.size()) {
System.out.print("Enter new task description: ");
tasks.set(updateIndex, scanner.nextLine());
System.out.println("Task updated successfully!");
} else {
System.out.println("Invalid task number!");
}
break;
case 5:
System.out.println("Exiting... Thank you for using the To-Do List!");
break;
default:
System.out.println("Invalid choice! Please try again.");
}
} while (choice != 5);
scanner.close();
}
}