-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_Manager.java
61 lines (52 loc) · 2.19 KB
/
Task_Manager.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
import java.io.*;
import java.util.Scanner;
public class Task_Manager {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
TaskList taskList = new TaskList("tasks.txt"); // Pass file name to TaskList
while (true) {
System.out.println("\n1. Add Task");
System.out.println("2. View Tasks");
System.out.println("3. Delete Task");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice;
if (sc.hasNextInt()) {
choice = sc.nextInt();
sc.nextLine(); // Consume the newline
} else {
System.out.println("Invalid input! Please enter a number.");
sc.next(); // Clear invalid input
continue;
}
switch (choice) {
case 1:
System.out.print("Enter Task Name: ");
String taskName = sc.nextLine();
System.out.print("Enter Task Description: ");
String taskDescription = sc.nextLine();
System.out.print("Enter Task Deadline: ");
String taskDeadline = sc.nextLine();
taskList.addTask(taskName, taskDescription, taskDeadline);
System.out.println("Task added successfully!");
break;
case 2:
System.out.println("\n--- Task List ---");
taskList.viewTasks();
break;
case 3:
System.out.print("Enter Task Name to delete: ");
String taskNameToDelete = sc.nextLine();
taskList.deleteTask(taskNameToDelete);
break;
case 4:
System.out.println("Exiting...");
sc.close();
System.exit(0);
break;
default:
System.out.println("Invalid Choice! Please try again.");
}
}
}
}