-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathJustin.java
More file actions
157 lines (108 loc) · 5.24 KB
/
Justin.java
File metadata and controls
157 lines (108 loc) · 5.24 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
import java.io.File;
import java.util.Scanner;
public class Justin {
private Storage storage;
private TaskList tasks;
private Ui ui;
public Justin(String filePath) {
ui = new Ui();
this.storage = new Storage(filePath);
tasks = storage.loadFile(filePath);
}
public void run() {
/*
* Justin is a chatbot that help users plan and organise tasks
* Justin stands for JUSt a TImetable(New) : JUSTIN
*
* Justin is able to create and manage new tasks
* 1) Mark tasks off as done
* 2) Set tasks as To Do's - <keyword> <name>
* 3) Set tasks as Deadline's - keyword : <keyword> <name> /by <day>
* 4) Set tasks as Event's - keyword : <keyword> <name> /at <day time>
* 5) Supports deletion of completed tasks with command delete <int>
*
* Justin also supports viewing the entire tasks list with the command list - keyword : <keyword>
* To end off the session user can input bye to terminate program - keyword : <keyword>
*
* @author Goh Wei Kiat aka github : mrweikiat
* @version CS2103T AY20/21 Semester 2, Individual Project 'IP'
*/
Scanner sc = new Scanner(System.in);
// Starting line for UI
ui.showWelcomeMessage();
ui.showHelpMessage();
// Condition for Duke to stop
boolean terminate = false;
//Duke will keep repeating until command given "Bye"
while (!terminate) {
String text = sc.nextLine();
Parser pr = new Parser(text);
try {
String command = pr.checkCommand();
switch (command) {
case "BYE":
storage.saveFile(tasks, storage.getFilePath());
terminate = true; // terminates Duke
ui.showEndMessage();
break;
case "LIST":
ui.showListMessage();
ui.printList(tasks);
break;
case "DONE":
String num = text.substring(5); // take out the int value of the task to be completed
int listNum = Integer.parseInt(num); // changes to int
Task hold = tasks.getList().get(listNum - 1);
hold.markAsDone();
ui.showDoneMessage(tasks, listNum);
break;
case "DEADLINE":
String newText = text.substring(9); // remove deadline from the string text
// set delimiter to take out the description of the deadline
String description = newText.substring(0, newText.indexOf("/") - 1);
// set delimiter to take out date of the deadline
String date = newText.substring(newText.indexOf("/") + 4);
ui.printLine();
tasks.addDeadline(description, date);
ui.printLine();
break;
case "TODO":
String descriptionToDo = text.substring(text.indexOf(" ") + 1); // take out the item from the text
tasks.addToDo(descriptionToDo);
break;
case "EVENT":
String eventText = text.substring(text.indexOf(" ") + 1); // removing the event to get description
// set delimiter to obtain the description and the at
String descriptionEvent = eventText.substring(0, eventText.indexOf("/") - 1);
String dateEvent = eventText.substring(eventText.indexOf("/") + 4);
// splitting the date and time respectively
tasks.addEvent(descriptionEvent, dateEvent);
break;
case "DELETE":
String numDelete = text.substring(7); // take out the int value of the task to be completed
tasks.delete(numDelete);
break;
case "FIND": // for level 9
String findText = text.substring(text.indexOf(" ")+1); // key for searching
ui.printFoundTask(tasks.find(findText));
break;
default:
ui.printLine();
System.out.println("added: " + text);
ui.printLine();
// create new instance of task and add to the list
Task holder = new Task(text);
tasks.getList().add(holder); // position corresponds to item number
}
} catch (JustinException m) {
ui.printErrorMessage(m.getMessage());
}
}
sc.close();
}
public static void main(String[]args){
String userDir = System.getProperty("user.dir");
String filePath = userDir + File.separator + "data" + File.separator + "justin.txt";
new Justin(filePath).run();
}
}