-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppManager.java
More file actions
158 lines (113 loc) · 4.54 KB
/
AppManager.java
File metadata and controls
158 lines (113 loc) · 4.54 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
package taskManager;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class AppManager {
private static final SimpleDateFormat properDate = new SimpleDateFormat("yyyy-MM-dd"); //import java simpledateformat so that we can make it so any date input has to follow this expectation
public static void main(String[] args) throws ParseException {
Manager newManager = new Manager();
Scanner scanner = new Scanner(System.in);
boolean exit = false;
while (exit != true) {
System.out.println("Welcome To the Assignment Manager System");
System.out.println("Please Choose one of the following \n1. Add Task \n2. Edit Task \n3. Remove Task \n4. View all Tasks \n5. Quit Application");
System.out.print("Choose an Action: ");
int pick = scanner.nextInt();
scanner.nextLine();
switch(pick) {
case 1:
addTask(newManager, scanner);
break;
case 2:
editTask(newManager, scanner);
break;
case 3:
deleteTask(newManager, scanner);
break;
case 4:
viewTasks(newManager);
break;
case 5:
exit = true;
System.out.println("Exiting Application");
break;
default:
System.out.println("Invalid Option");
break;
}
}
scanner.close();
}
private static Date parseDate(String dateString) throws ParseException {
try {
return properDate.parse(dateString);
}
catch (ParseException e){
System.out.println("Date Format is Invalid, Please use yyyy-MM-dd");
return null;
}
}
private static void addTask(Manager newManager, Scanner scanner) throws ParseException {
System.out.println("Enter Assignment Name: ");
String title = scanner.nextLine();
System.out.println("Enter Assignment Description: ");
String description = scanner.nextLine();
System.out.println("Enter the due Date (yyyy-MM-dd):");
Date dueDate = parseDate(scanner.nextLine());
if (dueDate == null) {
System.out.println("Invalid date, task not updated.");
return;
}
System.out.println("Enter the Priority (High, Medium, Low): ");
String priority = scanner.nextLine();
System.out.println("Enter the Class Code: ");
String classCode = scanner.nextLine();
System.out.println("Is the assignment complete (True/False): ");
boolean isFinished = scanner.nextBoolean();
newManager.addTask(title, description, dueDate, priority, classCode, isFinished);
System.out.println("Task has been added successfully");
}
private static void editTask(Manager newManager, Scanner scanner) throws ParseException {
System.out.println("Enter the Assignment ID to edit: ");
int id = scanner.nextInt();
scanner.nextLine();
System.out.println("Enter new Assignment Name: ");
String title = scanner.nextLine();
System.out.println("Enter new Assignment Description: ");
String description = scanner.nextLine();
System.out.println("Enter the new due Date (yyyy-MM-dd): ");
Date dueDate = parseDate(scanner.nextLine());
if (dueDate == null) {
System.out.println("Invalid date, task not updated.");
return;
}
System.out.println("Enter the new Priority (High, Medium, Low): ");
String priority = scanner.nextLine();
System.out.println("Enter the new Class Code: ");
String classCode = scanner.nextLine();
System.out.println("Is the assignment complete (True/False): ");
boolean isFinished = scanner.nextBoolean();
newManager.editTask(id, title, description, dueDate, priority, classCode, isFinished);
System.out.println("Task has been updated successfully");
}
private static void deleteTask(Manager newManager, Scanner scanner) {
System.out.println("Enter the Assignment ID that you want to delete: ");
int id = scanner.nextInt();
scanner.nextLine();
newManager.deleteTask(id);
System.out.println("Assignment has been Deleted");
}
private static void viewTasks(Manager newManager) {
List<Task> tasks = newManager.listTasks();
if (tasks.isEmpty()) {
System.out.println("No tasks available.");
}
else {
for (Task task : tasks) {
System.out.println(task);
}
}
}
}