diff --git a/Saved Progress/MY_GRAND_PLAN.txt b/Saved Progress/MY_GRAND_PLAN.txt index 91ddd37c56..ab913f1a72 100644 --- a/Saved Progress/MY_GRAND_PLAN.txt +++ b/Saved Progress/MY_GRAND_PLAN.txt @@ -1,3 +1,4 @@ -false TODO DRINK WATER -false TODO WATCH NGN +true TODO DRINK WATER +true TODO WATCH NGN false DEADLINE NGN /BY 20-02-2023 2359 +false TODO DRINK TEA diff --git a/src/main/java/duke/io/input/exception/UserInputException.java b/src/main/java/duke/io/input/exception/UserInputException.java index 21e5fb8beb..4e551d7025 100644 --- a/src/main/java/duke/io/input/exception/UserInputException.java +++ b/src/main/java/duke/io/input/exception/UserInputException.java @@ -1,8 +1,12 @@ package duke.io.input.exception; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; +import duke.util.Parser; + /** * An implementation of the {@code DukeException} template. It is used * to detect errors within user's input, and throw the corresponding @@ -27,74 +31,101 @@ public class UserInputException extends Exception { public static void checkUserInput(String input, int currentSize) throws DukeException { String[] inputSplitArray = input.split(" "); List inputSplitList = Arrays.asList(inputSplitArray); + int lengthOfCommand = inputSplitList.size(); + String command = inputSplitList.get(0); - if (command.equals("TODO")) { - if (inputSplitList.size() <= 1) { - throw new DukeException("EMPTY TO-DO COMMAND... DOING NOTHING MUCH?"); - } - } else if (command.equals("DEADLINE")) { - if (input.contains(" /BY ")) { - if (inputSplitList.size() <= 3) { - throw new DukeException("MORE INFO NEEDED FOR DEADLINE"); - } - } else { - throw new DukeException("NO DEADLINE. FREE TIME ISN'T SO EASY TO COME BY."); - } - } else if (command.equals("EVENT")) { - if (input.contains(" /FROM ") && input.contains(" /TO ")) { - if (inputSplitList.size() <= 5) { - throw new DukeException("MORE INFO NEEDED FOR EVENT"); - } - } else { - throw new DukeException("MY CREATOR DIDN'T MAKE ME SMART ENOUGH TO INFER INFO FROM THIS..."); - } - } else if (command.equals("MARK")) { - if (inputSplitList.size() == 1) { - throw new DukeException("MY CREATOR DIDN'T MAKE ME SMART ENOUGH TO INFER INFO FROM THIS..."); + if (command.equals("TODO") || command.equals("DEADLINE") || command.equals("EVENT")) { + checkParsingTask(input, lengthOfCommand); + } else if (command.equals("MARK") || command.equals("UNMARK") || command.equals("DELETE")) { + int requestedIndex = Integer.valueOf(inputSplitList.get(1)) - 1; + checkMarkingAndDelete(requestedIndex, lengthOfCommand, currentSize); + } else if (command.equals("LIST")) { + if (lengthOfCommand > 1) { + throw new DukeException("ARE YOU EXPECTING ME TO DO SOMETHING WITH THE EXTRA INFO?"); } - if (inputSplitList.size() > 2) { - throw new DukeException("TOO MUCH INFO..."); - } else { - if (Integer.valueOf(inputSplitList.get(1)) > currentSize) { - if (currentSize > 1) { - throw new DukeException("YOU ONLY HAVE " + currentSize + " TASKS"); - } else { - throw new DukeException("YOU ONLY HAVE " + currentSize + " TASK"); - } - } + } else if (command.equals("FIND")) { + if (lengthOfCommand > 2) { + throw new DukeException("THIS PLACE... IT MADE ME WEAK! I CAN ONLY SEARCH 1 KEYWORD NOW"); + } else if (lengthOfCommand == 1) { + throw new DukeException("WHAT EXACTLY DO YOU WANT TO FIND..."); } + } else if (command.equals("SCHEDULE")) { + checkSchedule(inputSplitList.get(1)); + } else { + throw new DukeException("COMMAND NOT FOUND... WHAT ARE YOU UP TO..."); + } + } - } else if (command.equals("UNMARK")) { - if (inputSplitList.size() == 1) { - throw new DukeException("MY CREATOR DIDN'T MAKE ME SMART ENOUGH TO INFER INFO FROM THIS..."); - } - if (inputSplitList.size() > 2) { - throw new DukeException("TOO MUCH INFO..."); - } else { - if (Integer.valueOf(inputSplitList.get(1)) > currentSize) { - throw new DukeException("YOU DON'T HAVE THAT MANY TASKS"); - } - } + private static void checkParsingTask(String input, int lengthOfCommand) throws DukeException { + String command = input.split(" ")[0]; + if (command.equals("TODO")) { + checkToDo(input, lengthOfCommand); + } else if (command.equals("DEADLINE")) { + checkDeadline(input, lengthOfCommand); + } else { + checkEvent(input, lengthOfCommand); + } + try { + Parser.parseTask(input); + } catch (Exception e) { + throw new DukeException("UH OH..." + e.getMessage()); + } + } - } else if (command.equals("DELETE")) { - if (inputSplitList.size() > 2) { - throw new DukeException("TOO MUCH INFO..."); - } else { - if (Integer.valueOf(inputSplitList.get(1)) > currentSize) { - throw new DukeException("YOU DON'T HAVE THAT MANY TASKS"); - } - } + private static void checkToDo(String input, int lengthOfCommand) throws DukeException { + if (lengthOfCommand <= 1) { + throw new DukeException("EMPTY TO-DO COMMAND... DOING NOTHING MUCH?"); + } + } - } else if (command.equals("LIST")) { - if (inputSplitList.size() > 1) { - throw new DukeException("ARE YOU EXPECTING ME TO DO SOMETHING WITH THE EXTRA INFO?"); + private static void checkDeadline(String input, int lengthOfCommand) throws DukeException { + if (input.contains(" /BY ")) { + if (lengthOfCommand <= 3) { + throw new DukeException("MORE INFO NEEDED FOR DEADLINE"); } - } else if (command.equals("FIND")) { + } else { + throw new DukeException("NO DEADLINE. FREE TIME ISN'T SO EASY TO COME BY."); + } + } - } else if (command.equals("SCHEDULE")) { + private static void checkEvent(String input, int lengthOfCommand) throws DukeException { + if (input.contains(" /FROM ") && input.contains(" /TO ")) { + if (lengthOfCommand <= 5) { + throw new DukeException("MORE INFO NEEDED FOR EVENT"); + } + } else { + throw new DukeException("MY CREATOR DIDN'T MAKE ME SMART ENOUGH TO INFER INFO FROM THIS..."); + } + } + private static void checkMarkingAndDelete(int requestedIndex, + int lengthOfCommand, + int currentSize) throws DukeException { + if (lengthOfCommand == 1) { + throw new DukeException("MY CREATOR DIDN'T MAKE ME SMART ENOUGH TO INFER INFO FROM THIS..."); + } else if (lengthOfCommand > 2) { + throw new DukeException("TOO MUCH INFO..."); } else { - throw new DukeException("COMMAND NOT FOUND... WHAT ARE YOU UP TO..."); + if (requestedIndex > currentSize) { + if (currentSize > 1) { + throw new DukeException("YOU ONLY HAVE " + currentSize + " TASKS"); + } else { + throw new DukeException("YOU ONLY HAVE " + currentSize + " TASK"); + } + } else if (requestedIndex < 0) { + throw new DukeException("BAD AT MATH? THAT INDEX DOESN'T EXIST"); + } + } + } + + private static void checkSchedule(String dateAsString) throws DukeException { + try { + DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + LocalDate scheduleDate = LocalDate.parse(dateAsString, dateFormat); + } catch (Exception e) { + throw new DukeException("WRONG DATE FORMAT... HOW FRUSTRATING"); } } } + + diff --git a/src/main/java/duke/io/input/ui/MainWindow.java b/src/main/java/duke/io/input/ui/MainWindow.java index b729a35342..f7d1f7dada 100644 --- a/src/main/java/duke/io/input/ui/MainWindow.java +++ b/src/main/java/duke/io/input/ui/MainWindow.java @@ -46,11 +46,11 @@ public MainWindow() { try { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource( "/view/MainWindow.fxml")); - fxmlLoader.setController(this); fxmlLoader.setRoot(this); + fxmlLoader.setController(this); fxmlLoader.load(); } catch (IOException exception) { - exception.printStackTrace();; + exception.printStackTrace(); } } @@ -73,6 +73,8 @@ public void greet() { Greeting greeting = new Greeting(); String response = UserInterface.printGuiLogo(); String toPrintOut = greeting.toString(); + System.out.println(DialogBox.getDukeDialog(response, dukeImage)); + System.out.println("I ran"); dialogContainer.getChildren().addAll( DialogBox.getDukeDialog(response, dukeImage), DialogBox.getDukeDialog(toPrintOut, dukeImage)); @@ -120,7 +122,6 @@ private int runDuke() { @FXML private void handleUserInput() { - getScene().getWindow().sizeToScene(); if (this.firstTimeRunningDukeFlag < 0) { firstTimeRunningDukeFlag = runDuke(); @@ -157,7 +158,6 @@ private void handleUserInput() { DialogBox.getUserDialog(input, userImage)); Storage.saveProgressGui(input, this.currentEvent.getTaskList()); - System.exit(0); } } else { return; diff --git a/src/main/java/duke/util/Storage.java b/src/main/java/duke/util/Storage.java index 672c4454b7..8ba51dd97e 100644 --- a/src/main/java/duke/util/Storage.java +++ b/src/main/java/duke/util/Storage.java @@ -34,6 +34,7 @@ public class Storage { private HashMap keywordDatabase; private HashMap>> taskScheduleOnDates; + /** * Construct the {@code Storage} object with * empty database diff --git a/src/main/resources/view/DialogBox.fxml b/src/main/resources/view/DialogBox.fxml index dac803c3cf..e6e3f441db 100644 --- a/src/main/resources/view/DialogBox.fxml +++ b/src/main/resources/view/DialogBox.fxml @@ -6,7 +6,7 @@ - +