diff --git a/src/main/java/commands/AddCommand.java b/src/main/java/commands/AddCommand.java index 5ffe310885..2610d79289 100644 --- a/src/main/java/commands/AddCommand.java +++ b/src/main/java/commands/AddCommand.java @@ -51,18 +51,16 @@ public AddCommand(String description, LocalDateTime startDate, LocalDateTime end * * @param tasks The task list where the task will be added. * @param storageManager The storage manager to save the changes. - * @return The added task. + * @return String print output. */ public String execute(TaskList tasks, StorageManager storageManager) { task.setStatus(status); tasks.add(task); storageManager.save(tasks); - StringBuilder output = new StringBuilder(); output.append("Got it. I've added this task:\n"); output.append(task).append("\n"); output.append(String.format("Now you have %d tasks in the list.\n", tasks.getSize())); - return output.toString(); } diff --git a/src/main/java/commands/ByeCommand.java b/src/main/java/commands/ByeCommand.java index 0340151ec0..1048648f83 100644 --- a/src/main/java/commands/ByeCommand.java +++ b/src/main/java/commands/ByeCommand.java @@ -12,7 +12,7 @@ public class ByeCommand extends Command { * * @param tasks The task list (not used in this command). * @param storageManager The storage manager (not used in this command). - * @return Null, as there is no task to return. + * @return String print output. */ public String execute(TaskList tasks, StorageManager storageManager) { return ("Bye. Hope to see you again soon!"); diff --git a/src/main/java/commands/Command.java b/src/main/java/commands/Command.java index fc472294a6..ae64fece18 100644 --- a/src/main/java/commands/Command.java +++ b/src/main/java/commands/Command.java @@ -13,7 +13,7 @@ public abstract class Command { * * @param tasks the taskList * @param storageManager to load and save tasks - * @return Task handled by the command + * @return String print output. * @throws CalException if there was an error when executing the command. */ public abstract String execute(TaskList tasks, StorageManager storageManager) throws CalException; diff --git a/src/main/java/commands/DeleteCommand.java b/src/main/java/commands/DeleteCommand.java index 634b33bb8f..53adbb8fa7 100644 --- a/src/main/java/commands/DeleteCommand.java +++ b/src/main/java/commands/DeleteCommand.java @@ -25,20 +25,17 @@ public DeleteCommand(int taskNum) { * * @param tasks The task list where the task will be deleted. * @param storageManager The storage manager to save the changes. - * @return The deleted task. + * @return String print output. */ public String execute(TaskList tasks, StorageManager storageManager) { Task t = tasks.delete(taskNum); storageManager.save(tasks); - StringBuilder output = new StringBuilder(); output.append("Noted. I've removed this task\n"); output.append(t).append("\n"); output.append(String.format("Now you have %d tasks in the list.\n", tasks.getSize())); - return output.toString(); } - /** * Indicates whether the DeleteCommand is an exit command. diff --git a/src/main/java/commands/FindCommand.java b/src/main/java/commands/FindCommand.java index 5a5b223a9a..e9a87cb1b4 100644 --- a/src/main/java/commands/FindCommand.java +++ b/src/main/java/commands/FindCommand.java @@ -27,7 +27,7 @@ public FindCommand(String keyword) { * * @param tasks The task list to search through * @param storageManager The storage manager (not used in this command). - * @return Null, as there is no task to return. + * @return String print output. */ public String execute(TaskList tasks, StorageManager storageManager) { StringBuilder output = new StringBuilder(); diff --git a/src/main/java/commands/ListCommand.java b/src/main/java/commands/ListCommand.java index 68e0a097ea..1734a30515 100644 --- a/src/main/java/commands/ListCommand.java +++ b/src/main/java/commands/ListCommand.java @@ -13,7 +13,7 @@ public class ListCommand extends Command { * * @param tasks The task list to be displayed. * @param storageManager The storage manager (not used in this command). - * @return Null, as there is no task to return. + * @return String print output. */ public String execute(TaskList tasks, StorageManager storageManager) { StringBuilder output = new StringBuilder(); @@ -28,7 +28,6 @@ public String execute(TaskList tasks, StorageManager storageManager) { } return output.toString(); } - /** * Indicates whether the ListCommand is an exit command. diff --git a/src/main/java/commands/MarkCommand.java b/src/main/java/commands/MarkCommand.java index ae50c1f4b0..19f30a68fc 100644 --- a/src/main/java/commands/MarkCommand.java +++ b/src/main/java/commands/MarkCommand.java @@ -26,20 +26,17 @@ public MarkCommand(int taskNum) { * * @param tasks The task list containing the task. * @param storageManager The storage manager to save the changes. - * @return The task that has been marked as done. + * @return String print output. * @throws CalException if the task number is invalid or if an error occurs. */ public String execute(TaskList tasks, StorageManager storageManager) throws CalException { Task t = tasks.mark(taskNum); storageManager.save(tasks); - StringBuilder output = new StringBuilder(); output.append("Nice! I've marked this task as done:\n"); output.append(t).append("\n"); - return output.toString(); } - /** * Indicates whether the MarkCommand is an exit command. diff --git a/src/main/java/commands/UnmarkCommand.java b/src/main/java/commands/UnmarkCommand.java index 37ec650c4b..2b204c7d79 100644 --- a/src/main/java/commands/UnmarkCommand.java +++ b/src/main/java/commands/UnmarkCommand.java @@ -27,20 +27,17 @@ public UnmarkCommand(int taskNum) { * * @param tasks The task list containing the task. * @param storageManager The storage manager to save the changes. - * @return The task that has been unmarked. + * @return String print output. * @throws CalException if the task number is invalid or if an error occurs. */ public String execute(TaskList tasks, StorageManager storageManager) throws CalException { Task t = tasks.unmark(taskNum); storageManager.save(tasks); - StringBuilder output = new StringBuilder(); output.append("OK, I've marked this task as not done yet:\n"); output.append(t).append("\n"); - return output.toString(); } - /** * Indicates whether the UnmarkCommand is an exit command. diff --git a/src/main/java/controller/DialogBox.java b/src/main/java/controller/DialogBox.java index 3edb4cccb3..b9fb163090 100644 --- a/src/main/java/controller/DialogBox.java +++ b/src/main/java/controller/DialogBox.java @@ -16,8 +16,8 @@ /** * An example of a custom control using FXML. - * This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label - * containing text from the speaker. + * represents a dialog box consisting of an ImageView to represent user profile picture and a label + * containing dialog text. */ public class DialogBox extends HBox { @FXML @@ -36,8 +36,8 @@ private DialogBox(String text, Image img, String backgroundColor) { } dialog.setText(text); displayPicture.setImage(img); - dialog.setStyle("-fx-background-color: " + backgroundColor - + "; -fx-background-radius: 10; " + "-fx-label-padding: 10;"); + dialog.setStyle("-fx-background-color: " + backgroundColor + + "; -fx-background-radius: 10; " + "-fx-label-padding: 10;"); } /** diff --git a/src/main/java/controller/MainWindow.java b/src/main/java/controller/MainWindow.java index 8503d751af..04162bb5e8 100644 --- a/src/main/java/controller/MainWindow.java +++ b/src/main/java/controller/MainWindow.java @@ -12,7 +12,8 @@ import javafx.scene.layout.VBox; /** - * The main view for the application. + * represents the main view for the application consisting of chat window, + * text field and send button. */ public class MainWindow { @FXML diff --git a/src/main/java/parser/Parser.java b/src/main/java/parser/Parser.java index da5a996700..9a2e613552 100644 --- a/src/main/java/parser/Parser.java +++ b/src/main/java/parser/Parser.java @@ -18,6 +18,18 @@ * contains a static method 'parseCommand' which takes a user input string and returns the appropriate Command object. */ public class Parser { + public static void checkNullTaskNum(int inputLen) throws CalException { + if (inputLen < 2) { + throw new CalException("Task number not provided!"); + } + } + + public static void checkBlankField(String field, String fieldName) throws CalException { + if (field.isBlank()) { + throw new CalException("Oops! You are missing" + fieldName + "."); + } + } + /** * Parses the user input string and returns the corresponding Command object. * @@ -40,23 +52,14 @@ public static Command parseCommand(String line) throws CalException { case "list": return new ListCommand(); case "mark": - if (tokens.length < 2) { - throw new CalException("Task number not provided!"); - } - + checkNullTaskNum(tokens.length); return new MarkCommand(Integer.parseInt(tokens[1])); case "unmark": - if (tokens.length < 2) { - throw new CalException("Task number not provided!"); - } - + checkNullTaskNum(tokens.length); return new UnmarkCommand(Integer.parseInt(tokens[1])); case "todo": description = line.substring(4).strip(); - if (description.isBlank()) { - throw new CalException("Task description not provided"); - } - + checkBlankField(description, "description"); return new AddCommand(description); case "deadline": int byIndex = line.indexOf("/by"); @@ -64,14 +67,9 @@ public static Command parseCommand(String line) throws CalException { try { description = line.substring(8, byIndex).strip(); - if (description.isBlank()) { - throw new CalException("Task description not provided"); - } - + checkBlankField(description, "description"); String by = line.substring(byIndex + 4).strip(); - if (by.isBlank()) { - throw new CalException("Task due date not provided"); - } + checkBlankField(by, "due date"); dueDate = LocalDateTime.parse(by, Task.INPUT_DATE_FORMAT); } catch (StringIndexOutOfBoundsException e) { throw new CalException("Deadline Task is not in the format: " @@ -89,20 +87,12 @@ public static Command parseCommand(String line) throws CalException { try { description = line.substring(5, fromIndex).strip(); - if (description.isBlank()) { - throw new CalException("Event description not provided"); - } - + checkBlankField(description, "description"); String startDateStr = line.substring(fromIndex + 5, toIndex).strip(); - if (startDateStr.isBlank()) { - throw new CalException("Event start date not provided"); - } + checkBlankField(startDateStr, "start date"); startDate = LocalDateTime.parse(startDateStr, Task.INPUT_DATE_FORMAT); - String endDateStr = line.substring(toIndex + 3).strip(); - if (endDateStr.isBlank()) { - throw new CalException("Event end date not provided"); - } + checkBlankField(endDateStr, "end date"); endDate = LocalDateTime.parse(endDateStr, Task.INPUT_DATE_FORMAT); } catch (StringIndexOutOfBoundsException e) { throw new CalException("Event Task is not in the format: " @@ -113,16 +103,11 @@ public static Command parseCommand(String line) throws CalException { return new AddCommand(description, startDate, endDate); case "delete": - if (tokens.length < 2) { - throw new CalException("Task number not provided!"); - } - + checkNullTaskNum(tokens.length); return new DeleteCommand(Integer.parseInt(tokens[1])); case "find": String keyword = line.substring(4).strip(); - if (keyword.isBlank()) { - throw new CalException("Missing search keyword."); - } + checkBlankField(keyword, "search keyword"); return new FindCommand(keyword); default: throw new CalException("Command not recognized."); diff --git a/src/main/java/storage/TaskSerializer.java b/src/main/java/storage/TaskSerializer.java index 733dff1c38..c2745c6ca2 100644 --- a/src/main/java/storage/TaskSerializer.java +++ b/src/main/java/storage/TaskSerializer.java @@ -22,7 +22,6 @@ public class TaskSerializer { */ public static String serialize(Task t) { assert t != null : "Task should not be null"; - String[] taskFields = {"", "", "", "", ""}; taskFields[1] = t.getStatus() ? "1" : "0"; taskFields[2] = t.getDescription();