This repository was archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathTaskManager.java
More file actions
96 lines (86 loc) · 3.22 KB
/
TaskManager.java
File metadata and controls
96 lines (86 loc) · 3.22 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
/*
This code below show the GUI application for managing a list of tasks,
Name: K V Deepak,
Task2: To Do List,
Java Internship Programming.
*/
import java.util.ArrayList;
import java.util.Scanner;
public class TaskManager {
private static ArrayList<String> tasks = new ArrayList<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean exit = false;
while (!exit) {
System.out.println("Task Manager");
System.out.println("1. Add Task");
System.out.println("2. Delete Task");
System.out.println("3. Mark Task as Completed");
System.out.println("4. View Tasks");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline character
switch (choice) {
case 1:
System.out.print("Enter task to add: ");
String taskToAdd = scanner.nextLine();
addTask(taskToAdd);
break;
case 2:
System.out.print("Enter index of task to delete: ");
int indexToDelete = scanner.nextInt();
scanner.nextLine(); // Consume newline character
deleteTask(indexToDelete);
break;
case 3:
System.out.print("Enter index of task to mark as completed: ");
int indexToComplete = scanner.nextInt();
scanner.nextLine(); // Consume newline character
markTaskAsCompleted(indexToComplete);
break;
case 4:
viewTasks();
break;
case 5:
exit = true;
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice. Please enter a number between 1 and 5.");
}
}
scanner.close();
}
private static void addTask(String task) {
tasks.add(task);
System.out.println("Task added successfully.");
}
private static void deleteTask(int index) {
if (index >= 0 && index < tasks.size()) {
tasks.remove(index);
System.out.println("Task deleted successfully.");
} else {
System.out.println("Invalid index. No task deleted.");
}
}
private static void markTaskAsCompleted(int index) {
if (index >= 0 && index < tasks.size()) {
String task = tasks.get(index);
tasks.set(index, "[Completed] " + task);
System.out.println("Task marked as completed.");
} else {
System.out.println("Invalid index. No task marked as completed.");
}
}
private static void viewTasks() {
if (tasks.isEmpty()) {
System.out.println("No tasks found.");
} else {
System.out.println("Tasks:");
for (int i = 0; i < tasks.size(); i++) {
System.out.println(i + ". " + tasks.get(i));
}
}
}
}