forked from nus-cs2103-AY2122S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Duke.java
59 lines (52 loc) · 1.28 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
56
57
58
59
package seedu.duke;
import seedu.commands.Command;
import seedu.storage.Storage;
import seedu.storage.TaskList;
/**
* Runner class for the application
*/
public class Duke {
private TaskList tasks;
private Parser parser;
private Storage storage;
private String path;
/**
* Constructor
*
* @param filePath file path of the save file
*/
public Duke(String filePath) {
parser = new Parser();
storage = new Storage(filePath);
try {
tasks = new TaskList(storage.load());
path = storage.getPath();
} catch (DukeException e) {
path = e.getMessage();
}
}
/**
* Bridge between gui and the application
*
* @param input The user input
* @return The response of the application
*/
public String getResponse(String input) {
try {
Command c = parser.parse(input);
String resp = c.execute(tasks);
storage.saveAll(tasks.getTasks());
return resp;
} catch (DukeException e) {
return e.getMessage();
}
}
/**
* Gets the file path of the save file
*
* @return The file path of the save file
*/
public String getPath() {
return path;
}
}