diff --git a/src/main/java/data/Duke.java b/src/main/java/data/Duke.java index 495c4961be..409a17d57e 100644 --- a/src/main/java/data/Duke.java +++ b/src/main/java/data/Duke.java @@ -106,6 +106,7 @@ public void runExit() { ui.displayMessage(SAVE_TASKLIST_TO_FILE_FAILURE_MESSAGE); } + ui.closeScanner(); ui.sayGoodbye(); System.exit(0); } diff --git a/src/main/java/ui/Ui.java b/src/main/java/ui/Ui.java index 048d078353..b4146a0919 100644 --- a/src/main/java/ui/Ui.java +++ b/src/main/java/ui/Ui.java @@ -4,6 +4,7 @@ import java.io.PrintStream; import java.util.Scanner; import common.Messages; +import data.Duke; import static common.Messages.START_MESSAGE; import static common.Messages.FIRST_EXIT_MESSAGE; @@ -67,6 +68,14 @@ public String getUserCommand() { return userInput; } + /** + * This method closes the Scanner object. + * Is used only when Duke executes {@link Duke#runExit()} + */ + public void closeScanner() { + this.in.close(); + } + /** * This methods prints out the message input, enclosed within underscored borders, for user to view. * @param message the message to be printed