-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCliBase.java
More file actions
77 lines (76 loc) · 2.9 KB
/
Copy pathCliBase.java
File metadata and controls
77 lines (76 loc) · 2.9 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
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class CliBase{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
List<Task> t = new ArrayList<>();
System.out.println("What you will perform?(Enter 'exit' to quit)");
int nextId = 1;
//loop runs continously so to stop it we should write a break statement;
while(true){
System.out.print("$ ");
String s = sc.next();
//statement to become true to break the loop
if(s.equalsIgnoreCase("exit")){
System.out.println("Exiting Program....");
break;
}else{
switch (s) {
case "add-task":
System.out.print("$ Enter the task : ");
String skip = sc.nextLine(); //as nextLine skips statement we are writing this skip scanner to deal with it
String addTask = sc.nextLine();
Task taskObject = new Task(addTask, nextId, false);
t.add(taskObject);
nextId++;
System.out.println("$ Task added Successfully");
break;
case "update-task":
System.out.print("$ Enter task number you want to mark as done : ");
int updateId = sc.nextInt();
boolean done = false;
int j = 0;
while(j < t.size()){
if(updateId == t.get(j).getId()){
t.get(j).setCompleted(true);
System.out.println("$ Marked as Done Successfully");
done = true;
break;
}
j++;
}
if(done == false){
System.out.println("$ Invalid Task!!");
}
break;
case "delete-task":
System.out.print("$ Enter task number you want to delete : ");
boolean found = false;
int deleteId = sc.nextInt();
for(int i = 0;i < t.size();i++){
if(deleteId == t.get(i).getId()){
t.remove(i);
found = true;
System.out.println("$ Task deleted successfully...");
break;
}
}
if(found == false){
System.out.println("$ Invalid Id task not found");
}
break;
case "list-task":
System.out.println("$ List of all the task : ");
// Iterating through the List
for (Task newTask : t){
System.out.println(newTask.toString());
}
break;
default:
break;
}
}
}
}
}