-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoListRun.java
More file actions
200 lines (165 loc) · 6.07 KB
/
TodoListRun.java
File metadata and controls
200 lines (165 loc) · 6.07 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package Z_GFG.ToDoAgain;
import java.util.*;
public class TodoListRun {
static Scanner in = new Scanner(System.in);
static ArrayList<String> listNames = new ArrayList<>();
static ArrayList<String> listOne = new ArrayList<>();
static ArrayList<ArrayList<String>> listTasks = new ArrayList<>();
static ArrayList<String> currentList;
static int index;
static class ToDoChoice {
static void ToDoChoice() {
System.out.println("ToDoList" + '\n' + "Choice :");
System.out.println("1. Create ToDo List");
System.out.println("2. Use ToDo List");
System.out.println("3. Remove ToDo List");
System.out.println("4. Quit");
System.out.println("Enter the choice number : ");
}
}
static class CreateToDoList {
public void CreateToDoList() {
while (true) {
Scanner in = new Scanner(System.in);
ArrayList<String> listOne = new ArrayList<>();
System.out.println("Enter List Name to be added :");
System.out.println("(Enter 'quit' to stop)");
String name = in.nextLine();
if (name.equals("quit")) {
break;
}
listNames.add(name);
System.out.println("Enter task to be added :");
System.out.println("(Enter 'quit' to stop.)");
while (true) {
String a = in.next();
if (a.equals("quit")) {
break;
}
listOne.add(a);
}
listTasks.add(listOne);
System.out.println("List tasks :" + listTasks);
currentList = listOne;
}
}
public void repeated(){
listOfToDo();
while (true) {
choice();
int no = in.nextInt();
if (no == 4) {
break;
}
switch (no) {
case 1:
addTask();
System.out.println(currentList);
break;
case 2:
removeTask();
break;
case 3:
mark();
break;
case 4:
break;
default:
System.out.println("Invalid input. Try again!");
}
}
}
}
static class UseToDoList extends CreateToDoList {
public void useToDo() {
if (listNames.isEmpty()) {
System.out.println("No list exits");
return;
}
repeated();
}
}
static class RemoveToDoList {
static void remove() {
if (listNames.isEmpty()) {
System.out.println("No list exits");
return;
}
listOfToDo();
listNames.remove(index);
listTasks.remove(index);
System.out.println("Remaining lists :" +listNames);
System.out.println(listTasks);
}
}
static void listOfToDo() {
Scanner n = new Scanner(System.in);
System.out.println("List Names :" + listNames);
System.out.println("Enter List Name to work on: ");
System.out.println("Enter 'quit' to stop");
String lName = n.nextLine();
if (lName.equals("quit")){
return;
}
int index = listNames.indexOf(lName);
currentList = listTasks.get(index);
System.out.println(currentList);
}
static void mark() {
System.out.println("Enter task number to be marked completed \u2705 : ");
int m = in.nextInt();
String n = currentList.get(m-1);
currentList.set(m-1, n + "\u2705");
System.out.println(currentList);
}
static void removeTask() {
System.out.println("Enter task number to be removed : ");
int t = in.nextInt();
currentList.remove(currentList.get(t - 1));
System.out.println(currentList);
}
static void addTask() {
System.out.println("Enter task :");
System.out.println("(Enter 'quit' to stop.)");
while (true) {
String p = in.next();
if (p.equals("quit")) {
break;
}
currentList.add(p);
}
}
static void choice() {
System.out.println("Choice :" + '\n' + "1. Add task" + '\n' +"2. Remove task"
+ '\n' + "3. Mark as completed" + '\n' + "4. quit"+ '\n' +
"Enter choice number :");
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ToDoChoice menu = new ToDoChoice();
while (true) {
menu.ToDoChoice();
int n = in.nextInt();
if (n == 4) {
System.out.println("ToDo List closed...");
break;
}
switch (n) {
case 1:
CreateToDoList create = new CreateToDoList();
create.CreateToDoList();
create.repeated();
break;
case 2:
UseToDoList use = new UseToDoList();
use.useToDo();
break;
case 3:
RemoveToDoList r = new RemoveToDoList();
r.remove();
default:
System.out.println("Invalid input. Try again!");
}
}
}
}