-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniTodoApp.java
More file actions
125 lines (100 loc) · 3.92 KB
/
MiniTodoApp.java
File metadata and controls
125 lines (100 loc) · 3.92 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.util.ArrayList;
import java.util.Scanner;
public class MiniTodoApp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Task> tasks = new ArrayList<>();
while (true) {
System.out.println("\n==== MINI TODO APP ====");
System.out.println("1) Add Task");
System.out.println("2) View Tasks");
System.out.println("3) Mark Task Done");
System.out.println("4) Delete Task");
System.out.println("5) Exit");
System.out.print("Choose: ");
int choice;
try {
choice = Integer.parseInt(sc.nextLine());
} catch (Exception e) {
System.out.println("❌ Invalid input. Enter a number (1-5).");
continue;
}
switch (choice) {
case 1:
System.out.print("Enter task title: ");
String title = sc.nextLine().trim();
if (title.isEmpty()) {
System.out.println("❌ Task title cannot be empty.");
break;
}
tasks.add(new Task(title));
System.out.println("✅ Task added.");
break;
case 2:
if (tasks.isEmpty()) {
System.out.println("⚠️ No tasks yet.");
break;
}
System.out.println("\n--- Tasks ---");
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ") " + tasks.get(i));
}
break;
case 3:
if (tasks.isEmpty()) {
System.out.println("⚠️ No tasks to mark.");
break;
}
System.out.print("Enter task number to mark done: ");
try {
int idx = Integer.parseInt(sc.nextLine()) - 1;
if (idx < 0 || idx >= tasks.size()) {
System.out.println("❌ Invalid task number.");
break;
}
tasks.get(idx).done = true;
System.out.println("✅ Marked as done.");
} catch (Exception e) {
System.out.println("❌ Invalid input. Enter a valid task number.");
}
break;
case 4:
if (tasks.isEmpty()) {
System.out.println("⚠️ No tasks to delete.");
break;
}
System.out.print("Enter task number to delete: ");
try {
int idx = Integer.parseInt(sc.nextLine()) - 1;
if (idx < 0 || idx >= tasks.size()) {
System.out.println("❌ Invalid task number.");
break;
}
tasks.remove(idx);
System.out.println("✅ Task deleted.");
} catch (Exception e) {
System.out.println("❌ Invalid input. Enter a valid task number.");
}
break;
case 5:
System.out.println("✅ Exiting...");
sc.close();
return;
default:
System.out.println("❌ Choose between 1 to 5 only.");
}
}
}
}
class Task {
String title;
boolean done;
Task(String title) {
this.title = title;
this.done = false;
}
@Override
public String toString() {
return (done ? "[X] " : "[ ] ") + title;
}
}