blob: d839da8d71d37d1992de86be41fd09504197e3c3 (
plain)
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
|
package lk.ac.pdn.ceit.tasks.ui;
import lk.ac.pdn.ceit.tasks.TaskManager;
import lk.ac.pdn.ceit.tasks.entities.Task;
public class TextUI {
private TaskManager taskManager;
public void setTaskManager(TaskManager taskManager) {
this.taskManager = taskManager;
}
public void start() {
while(true) {
String command = IO.readln("Command> ");
switch (command.trim().toLowerCase()) {
case "q":
case "quit":
IO.println("Thank you for using Task Tracker.");
System.exit(0);
case "createtask":
createNewTask();
break;
case "updatetask":
updateTask();
break;
default:
IO.println("Command not found.");
break;
}
}
}
private void createNewTask() {
String title = IO.readln("Enter task title: ");
String description = IO.readln("Enter task description: ");
Task newTask = taskManager.createNewTask(title, description);
IO.println("New task created: " + newTask);
}
private void updateTask() {
// Ask the user to enter task id
String taskId = IO.readln("Enter task ID: ");
// Get the Task from TaskManager
Task task = taskManager.findById(Integer.parseInt(taskId));
// Show the Task details to user
IO.print(task);
// Prompt the user to update Task properties
String title = IO.readln("New title: ");
if (! title.equals("")) {
task.setTitle(title);
}
// ...
// Use the TaskManager and update the task
taskManager.updateTask(task);
IO.println("Task updated.");
}
}
|