-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathDuke.java
More file actions
49 lines (45 loc) · 1.19 KB
/
Duke.java
File metadata and controls
49 lines (45 loc) · 1.19 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
package Duke;
import Duke.Parser.Parser;
import Duke.DukeException.DukeException;
import Duke.Command.*;
import Duke.Storage.Storage;
import Duke.Ui.Ui;
import Duke.Tasks.TaskList;
public class Duke {
private Storage storage;
private TaskList tasks;
private Ui ui;
public Duke(String filePath) {
ui = new Ui();
storage = new Storage(filePath);
try {
tasks = new TaskList(storage.load());
} catch (DukeException e) {
ui.showLoadingError();
tasks = new TaskList();
}
}
/**
* Run the program.
*/
public void run() {
ui.showWelcome();
boolean isExit = false;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine();
Command c = Parser.parse(fullCommand);
c.execute(tasks, ui, storage);
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
} finally {
ui.showLine();
}
}
}
public static void main(String[] args) {
new Duke(".\\tasks.txt").run();
}
}