-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManagerMain.java
More file actions
104 lines (98 loc) · 2.59 KB
/
TaskManagerMain.java
File metadata and controls
104 lines (98 loc) · 2.59 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
import java.util.Scanner;
class Task{
private final String description;
private boolean isCompleted;
Task(String description){
this.description=description;
}
boolean isComplete() {
return this.isCompleted;
}
void markCompleted() {
this.isCompleted=true;
}
@Override
public String toString() {
return "Task Description="+this.description+"\n Completed Status="+this.isCompleted;
}
}
class TaskManager{
Task task[];
int taskCount;
TaskManager(int intialCompasity){
task=new Task[intialCompasity];
}
void addTask(String description) {
if(taskCount==task.length) {
System.out.println("Task List Is Full");
}else {
Task t=new Task(description);
task[taskCount]=t;
taskCount++;
System.out.println("Task Added Succussfully...");
}
}
void markTaskCompleted(int index){
task[index-1].markCompleted();
System.out.println("Task Completed Status Updated...");
}
void listPendingTasks() {
for(int i=0;i<task.length;i++) {
if(task[i].isComplete()==false) {
System.out.println(task[i]);
}
if(task[i+1]==null)break;
}
}
void listCompletedTasks() {
for(int i=0;i<task.length;i++) {
if(task[i].isComplete()==true) {
System.out.println(task[i]);
}
if(task[i+1]==null)break;
}
}
void listAllTasks() {
for(int i=0;i<taskCount;i++) {
System.out.println(task[i]);
}
}
}
public class TaskManagerMain {
public static void main(String[] args) {
TaskManager tm=new TaskManager(10);
Scanner sc=new Scanner(System.in);
boolean isExit=false;
while(!isExit) {
System.out.println("1.Add Task");
System.out.println("2.Mark Task as Complete");
System.out.println("3.List completed Tasks");
System.out.println("4.List Pending Tasks");
System.out.println("5.List all Tasks");
System.out.println("6.Exit");
System.out.print("Enter Option:");
int op=sc.nextInt();
sc.nextLine();
switch(op) {
case 1 -> {
System.out.println("Enter Your Task info:");
String desc=sc.nextLine();
tm.addTask(desc);
}
case 2 -> {
tm.listPendingTasks();
System.out.println("Enter Task Number:");
int index=sc.nextInt();
tm.markTaskCompleted(index);
}
case 3 -> tm.listCompletedTasks();
case 4 -> tm.listPendingTasks();
case 5 -> tm.listAllTasks();
case 6 -> {
isExit=true;sc.close();
}
default -> System.out.println("Invalid Input");
}
}
}
}