-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathToDoList.java
76 lines (69 loc) · 2.28 KB
/
ToDoList.java
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
package Programs;
import java.util.ArrayList;
import java.util.Scanner;
public class ToDoList {
public static void main(String[] args) {
ArrayList<String> tasks = new ArrayList<>();
list(tasks);
}
public static void list(ArrayList<String> tasks) {
Scanner sc = new Scanner(System.in);
System.out.print("Function you want to apply(1-4):\n"
+ "1- View\n"
+ "2- Add\n"
+ "3- Delete All Tasks\n"
+ "> ");
int desiredFunction = sc.nextInt();
choose(desiredFunction, tasks, sc);
}
public static void choose(int desiredFunction, ArrayList<String> tasks, Scanner sc) {
if (desiredFunction == 1) {
viewTask(tasks);
} else if (desiredFunction == 2) {
addTask(tasks);
} else if (desiredFunction == 3) {
deleteTasks(tasks);
} else {
System.out.println("Please choose in the range of 1 till 3 only!");
list(tasks);
}
}
static void addTask(ArrayList<String> tasks) {
Scanner sc = new Scanner(System.in);
System.out.print("Task to save\n> ");
tasks.add(sc.nextLine());
System.out.print("Add more?\n 1- Yes\n 2- No\n> ");
int yn = sc.nextInt();
if (yn == 1) {
addTask(tasks);
} else if (yn == 2){
list(tasks);
} else {
System.out.println("Invalid number!");
addTask(tasks);
}
}
static void viewTask(ArrayList<String> tasks) {
if (tasks.isEmpty()) {
System.out.println("""
--------------------
No current tasks!
--------------------""");
} else {
System.out.println("""
--------------------
Tasks
--------------------""");
int counter = 1;
for (int i = 0; i < tasks.size(); i++) {
System.out.println(counter + "- " + tasks.get(i));
counter++;
}
}
System.out.println("\nSelect from the following commands:");
list(tasks);
}
static void deleteTasks(ArrayList<String> tasks) {
tasks.clear();
}
}