-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathDuke.java
More file actions
53 lines (49 loc) · 1.3 KB
/
Duke.java
File metadata and controls
53 lines (49 loc) · 1.3 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
53
import java.util.Scanner;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.IOException;
/*
* The main class for the Duke app.
*/
public class Duke {
private Storage storage;
private TaskList tasks;
private Ui ui;
public Duke(String filePath) {
ui = new Ui();
storage = new Storage(filePath);
tasks = new TaskList();
}
/*
* Run the Duke app.
*/
public void run() {
Scanner sc = new Scanner(System.in);
ui.reply();
Path path = Paths.get(this.storage.getFilePath());
if (Files.exists(path)) {
this.tasks = storage.readFromFile();
} else {
try {
Files.createDirectories(path.getParent());
Files.createFile(path);
} catch (IOException e) {
e.printStackTrace();
}
}
Parser parser = new Parser(tasks, ui, storage);
while (true) {
String command = sc.nextLine();
parser.insertCommand(command);
parser.process();
if (parser.isFinished()) {
break;
}
}
System.exit(0);
}
public static void main(String[] args) {
new Duke("./data/duke.txt").run();
}
}