-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathDuke.java
More file actions
55 lines (46 loc) · 1.39 KB
/
Duke.java
File metadata and controls
55 lines (46 loc) · 1.39 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
import duke.exception.DukeException;
import duke.task.TaskBank;
import java.util.Scanner;
public class Duke {
private Storage storage;
private TaskBank taskBank;
private Ui ui;
private static boolean isTerminating;
/**
* Instantiates Storage, TaskBank and Ui of the programme
* @param filePath the filePath which duke.txt is stored
*/
public Duke(String filePath) {
ui = new Ui();
taskBank = new TaskBank();
storage = new Storage(filePath, taskBank, ui);
}
/**
* Runs Duke program
*/
public void run() {
try (Scanner sc = new Scanner(System.in)) {
String fullCommand;
while (!isTerminating) {
fullCommand = ui.readInput(sc);
ui.printDashLine();
Action action = Parser.parseCommand(fullCommand);
Command.perform(fullCommand, action, ui, storage, taskBank);
ui.printDashLine();
}
} catch (DukeException e) {
ui.showErrorMessage(e);
}
}
public static void main(String[] args) {
isTerminating = false;
new Duke("./data/duke.txt").run();
}
/**
* Changes the variable isTerminating to true
* Used to end the while loop that continuously read user input
*/
public static void terminateDuke() {
isTerminating = true;
}
}