diff --git a/data/duke.txt b/data/duke.txt index 838b24cfda..ed696b1939 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,5 +1,5 @@ D | 0 | test dates correct deadline | 2023-10-21 | null -E | 1 | correct event timings | 2222-11-11 | 2222-11-13 +E | 0 | correct event timings | 2222-11-11 | 2222-11-13 D | 1 | Dead Package bruh | 1111-11-11 | null T | 0 | After Checkstyle | null | null D | 0 | VIEWSCHEDULE BRO | 2023-09-14 | null diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java index 172126affa..4f6420d93b 100644 --- a/src/main/java/duke/DialogBox.java +++ b/src/main/java/duke/DialogBox.java @@ -37,7 +37,7 @@ private DialogBox(String text, Image img) { dialog.setText(text); dialog.setMinHeight(Region.USE_PREF_SIZE); - Circle circleClip = new Circle(40,30,30); + Circle circleClip = new Circle(40, 30, 30); displayPicture.setImage(img); displayPicture.setClip(circleClip); } diff --git a/src/main/java/duke/util/Parser.java b/src/main/java/duke/util/Parser.java index 18db5df956..aaed09acdf 100644 --- a/src/main/java/duke/util/Parser.java +++ b/src/main/java/duke/util/Parser.java @@ -1,9 +1,7 @@ package duke.util; import java.io.IOException; -import java.time.LocalDate; -import duke.Duke; import duke.exception.EmptyDescriptionException; import duke.exception.InvalidCommandException; import duke.exception.InvalidDateException; @@ -22,8 +20,6 @@ * @author Freddy Chen You Ren */ public class Parser { - //60 underscores. - private static final String HORIZONTAL_LINE = " ____________________________________________________________"; private TaskList taskList; private Ui ui; @@ -68,9 +64,10 @@ private String getCommand(String line) { * - find (keyword}: to find the list of tasks that contains the corresponding keyword. * - deadline {taskname} /by {time}: to add a new task as a deadline task. * - todo {taskname}: to add a new task as a to-do item. (No need to provide time). - * - event {taskname} /from {starttime} /to {endtime}: to add a new task as an event task (with given start time and end time). + * - event {taskname} /from {starttime} /to {endtime}: to add a new task as an event task. * - view {date}: list down the tasks that are to be done on that day. - * Note that the commands are not case-sensitive. For instance: "BYE", "ByE", "bYe" will all be treated as the "bye" command. + * Note that the commands are not case-sensitive. + * For instance: "BYE", "ByE", "bYe" will all be treated as the "bye" command. * * @param userInput The user's input to be parsed. */ @@ -138,11 +135,12 @@ private String handleFindTask(String userInput) { } private String handleException(Exception e) { if (e instanceof IllegalArgumentException) { - InvalidCommandException exception = new InvalidCommandException("I'm sorry, but I don't know what that means :-("); + InvalidCommandException exception = new InvalidCommandException( + "I'm sorry, but I don't know what that means :-("); return exception.toString(); } - if (e instanceof EmptyDescriptionException || - e instanceof IOException || e instanceof InvalidDateException) { + if (e instanceof EmptyDescriptionException || e instanceof IOException + || e instanceof InvalidDateException) { return e.toString(); } else { return "Very Invalid command! Please enter valid commands"; diff --git a/src/main/java/duke/util/Storage.java b/src/main/java/duke/util/Storage.java index 11c3057b1d..cd17f3cedf 100644 --- a/src/main/java/duke/util/Storage.java +++ b/src/main/java/duke/util/Storage.java @@ -2,7 +2,6 @@ import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; diff --git a/src/main/java/duke/util/TaskList.java b/src/main/java/duke/util/TaskList.java index ac26bd4b36..cbcd347548 100644 --- a/src/main/java/duke/util/TaskList.java +++ b/src/main/java/duke/util/TaskList.java @@ -27,7 +27,7 @@ public class TaskList { //60 underscores. protected static String HORIZONTAL_LINE = " ____________________________________________________________"; protected Storage storage; - protected ArrayList listOfTasks; + protected ArrayList listOfTasks; /** * Instantiates a TaskList with the given storage. @@ -70,12 +70,11 @@ protected String listAllTasks() { * * @param deleteInput The input representing the delete command. * It should contain task index to be deleted. + * @return The message to indicate which task has been deleted after successful deletion. * @throws EmptyDescriptionException If there is no task index provided. * @throws IOException If there is an error updating the data file. - * @return The message to indicate which task has been deleted after successful deletion. */ - public String deleteTask(String deleteInput) - throws EmptyDescriptionException, IOException { + public String deleteTask(String deleteInput) throws EmptyDescriptionException, IOException { String[] words = deleteInput.split("\\s+"); // Split input by space, put into array StringBuilder message = new StringBuilder(); @@ -84,31 +83,23 @@ public String deleteTask(String deleteInput) throw new EmptyDescriptionException("Please provide the task index to be deleted."); } - //Try parsing into integer to get deleteIndex try { int deleteIndex = Integer.parseInt(words[1]) - 1; if (deleteIndex >= 0 && deleteIndex < listOfTasks.size()) { Task removedTask = listOfTasks.remove(deleteIndex); storage.clearAllData(); storage.updateData(); - assert !listOfTasks.contains(removedTask) : "Task should have been removed!"; - message.append("Noted. I've removed this task:\n"); message.append(String.format("%s\n", removedTask.toString())); message.append(String.format("Now you have %d task(s) in the list.\n", listOfTasks.size())); - System.out.println(" Noted. I've removed this Task:"); - System.out.printf(" %s\n", removedTask); - System.out.printf(" Now you have %d task(s) in the list.\n", listOfTasks.size()); } else { message.append("OOPS!!! The task index is invalid.\n"); message.append(String.format("You currently have %d task(s).\n", listOfTasks.size())); - System.out.printf(" You currently have %d task(s).\n", listOfTasks.size()); } return message.toString(); } catch (NumberFormatException e) { - message.append("OOPS!!! Please enter the index after 'delete' command."); - message.append("For example: delete 5"); + message.append("OOPS!!! Please enter the index after 'delete' command.\nFor example: delete 5"); message.append("This will remove Task 5 from your Task List, assuming you have at least 5 tasks."); return message.toString(); } @@ -120,8 +111,8 @@ public String deleteTask(String deleteInput) * Prints out an error message if index of the task given is out of range or invalid. * * @param taskIndex The index of the Task to be marked as done. - * @throws IOException If there is an issue with updating the data in the storage file. * @return The message to indicate that the task is marked as done. + * @throws IOException If there is an issue with updating the data in the storage file. */ protected String markTask(int taskIndex) throws IOException { StringBuilder message = new StringBuilder(); @@ -130,16 +121,12 @@ protected String markTask(int taskIndex) throws IOException { } else { Task task = listOfTasks.get(taskIndex); task.markAsDone(); - assert listOfTasks.get(taskIndex).getStatus() : "Task must be marked done."; - storage.clearAllData(); storage.updateData(); message.append("Nice! I've marked this Task as done:\n"); message.append(String.format("\t[%s] %s\n", task.getStatusIcon(), task.getDescription())); - System.out.println(" Nice! I've marked this Task as done:"); - System.out.printf(" [%s] %s\n", task.getStatusIcon(), task.getDescription()); } return message.toString(); } @@ -150,8 +137,8 @@ protected String markTask(int taskIndex) throws IOException { * Prints out an error message if index of the task given is out of range or invalid. * * @param taskIndex The index of the Task to be marked as not done yet. - * @throws IOException If there is an issue with updating the data in the storage file. * @return The message to indicate that the task is marked as not done yet. + * @throws IOException If there is an issue with updating the data in the storage file. */ protected String unmarkTask(int taskIndex) throws IOException { StringBuilder message = new StringBuilder(); @@ -160,9 +147,7 @@ protected String unmarkTask(int taskIndex) throws IOException { } else { Task task = listOfTasks.get(taskIndex); task.markAsNotDone(); - assert !listOfTasks.get(taskIndex).getStatus() : "Task must be marked NOT done yet."; - storage.clearAllData(); storage.updateData(); @@ -222,6 +207,9 @@ public static boolean isValidDate(String testDate) { * @return The message representing the tasks found using the keyword provided. */ protected String findTask(String matchingKeyword) { + if (matchingKeyword.trim().isEmpty()) { + return "Please provide the keyword you wish to find :)"; + } if (listOfTasks.isEmpty()) { System.out.println("\t You currently have no tasks so I can't find any matching tasks :/."); return "\t You currently have no tasks so I can't find any matching tasks :("; @@ -237,7 +225,7 @@ protected String findTask(String matchingKeyword) { taskCount++; } } - + //Output matching tasks if (taskCount > 0) { return matchingTasks.toString(); @@ -253,7 +241,7 @@ protected String viewSchedule(String userInput) throws InvalidDateException { if (details.length <= 1) { return "Invalid input. Please key in `view YYYY-MM-DD` format."; } - String requestedDate = details[1].trim(); // Get requested date + String requestedDate = details[1].trim(); // Get requested date if (!isValidDate(requestedDate)) { throw new InvalidDateException(); @@ -262,8 +250,8 @@ protected String viewSchedule(String userInput) throws InvalidDateException { String requestedDateString = LocalDate.parse(requestedDate).format(DateTimeFormatter.ofPattern("MMM d yyyy")); ArrayList scheduledTasks = printSchedule(LocalDate.parse(requestedDate)); if (scheduledTasks.size() == 0) { - return String.format("There is no tasks happening on %s. ", requestedDateString) + - "Please double check your list of tasks."; + return String.format("There is no tasks happening on %s. ", requestedDateString) + + "Please double check your list of tasks."; } StringBuilder message = new StringBuilder( diff --git a/src/main/java/duke/util/Ui.java b/src/main/java/duke/util/Ui.java index e3f3695966..2ffa3acaf2 100644 --- a/src/main/java/duke/util/Ui.java +++ b/src/main/java/duke/util/Ui.java @@ -1,10 +1,11 @@ package duke.util; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; + import duke.Duke; import javafx.application.Platform; -import java.util.Scanner; -import java.util.concurrent.TimeUnit; /** * Represents a user interface for SeeWhyAre bot. @@ -33,10 +34,6 @@ protected String printHorizontalLine() { return HORIZONTAL_LINE; } - public Ui getUi() { - return this; - } - /** * Displays a greeting message to the user. */