diff --git a/data/duke.txt b/data/duke.txt index b38632abec..55694913ee 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,2 +1 @@ -TODO | 1 | watch movies -DEADLINE | 0 | submit user guide | 2024-12-31 \ No newline at end of file +TODO | 1 | test \ No newline at end of file diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 882f48db8d..3af4f824d4 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -11,10 +11,10 @@ public class Duke { private static final String SAVING_ERROR_MSG = "⚠ Oops! Something wrong when closing:("; private static final String BYE_MSG = "Bye!\n\"Beware the barrenness of a busy life.\""; - private Parser parser; - private Storage storage; - private TaskList tasks; - private Stage stage; + private final Parser parser; + private final Storage storage; + private final TaskList tasks; + private final Stage stage; /** * Initializes the chat robot. Establishes task list and parser. @@ -40,12 +40,15 @@ public Duke(Stage stage) { public String getResponse(String input) { try { String output = parser.parse(input); + this.storage.save(this.tasks); if (!parser.isRunning()) { return exit(); } return output; } catch (DukeException e) { return handleException(e); + } catch (IOException e) { + return handleException(new DukeException("saving error")); } } @@ -81,6 +84,9 @@ private String handleException(DukeException e) { case "undefined": warning = "⚠ Sorry! I am not able to understand you. Try another language:D"; break; + case "saving error": + warning = SAVING_ERROR_MSG; + break; default: warning = "⚠ Oops! Something went wrong:("; break;