forked from nus-cs2103-AY2122S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Duke.java
55 lines (44 loc) · 1.43 KB
/
Duke.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
package duke.main;
import java.io.IOException;
import duke.commands.Command;
import duke.common.DukeException;
import duke.constants.Constants;
import duke.parser.Parser;
import duke.storage.Storage;
import duke.task.TaskList;
/**
* Acts as a task manager that keeps tracks of all your tasks.
*/
public class Duke {
private final Storage storage;
private TaskList taskList;
/**
* Creates a Duke object that initializes all the necessary components for the task manager program.
*/
public Duke() {
this.taskList = new TaskList();
this.storage = new Storage(Constants.FILE_PATH + Constants.FILE_NAME);
try {
this.taskList = new TaskList(storage.loadFromFile());
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* You should have your own function to generate a response to user input.
* Replace this stub with your completed method.
*/
public String getResponse(String input) {
assert input != null : "Duke[getResponse] input cannot be null.";
assert input.length() > 0 : "Duke[getResponse] input must contain data.";
String response;
try {
Parser parser = new Parser(input);
Command c = parser.parse();
response = c.execute(taskList, storage);
} catch (DukeException e) {
response = e.getMessage();
}
return response;
}
}