-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDoList.java
More file actions
42 lines (38 loc) · 1.51 KB
/
ToDoList.java
File metadata and controls
42 lines (38 loc) · 1.51 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
import java.util.ArrayList;
import java.util.Scanner;
public class ToDoList {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> tasks = new ArrayList<>();
String command;
while (true) {
System.out.println("Enter command (add, view, remove, quit):");
command = scanner.nextLine();
if (command.equals("add")) {
System.out.println("Enter task to add:");
String task = scanner.nextLine();
tasks.add(task);
} else if (command.equals("view")) {
System.out.println("Your tasks:");
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ". " + tasks.get(i));
}
} else if (command.equals("remove")) {
System.out.println("Enter task number to remove:");
int taskNum = scanner.nextInt();
scanner.nextLine(); // Consume newline
if (taskNum > 0 && taskNum <= tasks.size()) {
tasks.remove(taskNum - 1);
System.out.println("Task removed.");
} else {
System.out.println("Invalid task number.");
}
} else if (command.equals("quit")) {
break;
} else {
System.out.println("Unknown command.");
}
}
scanner.close();
}
}