-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathDuke.java
More file actions
52 lines (44 loc) · 1.26 KB
/
Duke.java
File metadata and controls
52 lines (44 loc) · 1.26 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
package duke;
import duke.command.Command;
import duke.exception.DukeException;
import java.util.ArrayList;
/**
* the agent program to run duke.Duke
*/
public class Duke {
private static final String FILE_PATH = "./data/duke.txt";
private Ui ui;
private TaskList tasks;
private Storage storage;
private Parser parser;
public Duke() {
this.ui = new Ui();
this.parser = new Parser();
this.storage = new Storage(FILE_PATH);
try {
this.tasks = new TaskList(storage.load());
} catch (DukeException e) {
ui.printMsg(e.getMessage());
this.tasks = new TaskList(new ArrayList<>());
}
}
public static void main(String[] args) {
new Duke().run();
}
public void run() {
ui.printGreetingMsg();
boolean isExit = false;
while(!isExit) {
String fullCommand = ui.readCommand();
ui.printLine();
try {
Command command = parser.parseCommand(fullCommand);
command.execute(tasks, ui, storage);
isExit = command.isExit();
} catch (DukeException e) {
ui.printMsg(e.getMessage());
}
ui.printLine();
}
}
}