From f070266d97a2d3abf2839e3461233fa43bce0499 Mon Sep 17 00:00:00 2001 From: quelinxiao <122249170+quelinxiao@users.noreply.github.com> Date: Mon, 26 Feb 2024 03:07:56 +0800 Subject: [PATCH] Improve code quality --- src/main/java/bob/Bob.java | 6 +-- src/main/java/bob/Event.java | 12 ++--- src/main/java/bob/MainWindow.java | 1 + src/main/java/bob/Parser.java | 60 +++++++++++++++++++----- src/main/java/bob/Storage.java | 6 +-- src/main/java/bob/Task.java | 16 +++---- src/main/java/bob/TaskList.java | 22 ++++----- src/main/java/bob/ToDo.java | 6 +-- src/main/java/bob/Ui.java | 78 ++++++++++++++++++++++++------- 9 files changed, 143 insertions(+), 64 deletions(-) diff --git a/src/main/java/bob/Bob.java b/src/main/java/bob/Bob.java index 31e73ca271..ce532150dd 100644 --- a/src/main/java/bob/Bob.java +++ b/src/main/java/bob/Bob.java @@ -29,7 +29,7 @@ public class Bob extends Application{ private Image user = new Image(this.getClass().getResourceAsStream("/images/DaUser.png")); private Image duke = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png")); - /* + /** * A constructor for the chatbot Bob. */ public Bob(String filePath) { @@ -39,7 +39,7 @@ public Bob(String filePath) { this.parser = new Parser(ui); } - /* + /** * A no argument constructor for launcher. */ public Bob() { @@ -49,7 +49,7 @@ public Bob() { this.parser = new Parser(ui); } - /* + /** * A method that signals the chatbot to start its processes. */ public void run() { diff --git a/src/main/java/bob/Event.java b/src/main/java/bob/Event.java index 21db2affb8..326d32d3df 100644 --- a/src/main/java/bob/Event.java +++ b/src/main/java/bob/Event.java @@ -2,14 +2,14 @@ import java.util.Objects; -/* +/** * This class represents an event that can be recorded in the tasklist. */ class Event extends Task { protected String from; protected String to; - /* + /** * A constructor to create a new event task. */ public Event(String description, String from, String to) { @@ -18,7 +18,7 @@ public Event(String description, String from, String to) { this.to = to; } - /* + /** * A method to get from. * * @return The start date of the event. @@ -27,7 +27,7 @@ public String getFrom() { return this.from; } - /* + /** * A method to get to. * * @return The end date of the event. @@ -36,7 +36,7 @@ public String getTo() { return this.to; } - /* + /** * A method that returns the status of the task. * * @return A label [E] and a check-box followed by the description of the task. @@ -46,7 +46,7 @@ public String toString() { return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; } - /* + /** * A method to check if two objects are equal. * * @param o The object to compare to. diff --git a/src/main/java/bob/MainWindow.java b/src/main/java/bob/MainWindow.java index 3193d06cad..354ffe0219 100644 --- a/src/main/java/bob/MainWindow.java +++ b/src/main/java/bob/MainWindow.java @@ -7,6 +7,7 @@ import javafx.scene.image.Image; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; + /** * Controller for MainWindow. Provides the layout for the other controls. */ diff --git a/src/main/java/bob/Parser.java b/src/main/java/bob/Parser.java index a520a7c69e..2971a577e6 100644 --- a/src/main/java/bob/Parser.java +++ b/src/main/java/bob/Parser.java @@ -4,21 +4,25 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -/* +/** * This class makes sense of the user's commands. */ public class Parser { private Ui ui; - /* + /** * A constructor that assigns a UI to the parser. */ public Parser(Ui ui) { this.ui = ui; } - /* + /** * A method to parse the user command 'exit'. + * + * @param storage The file we want to save our task list to. + * @param taskList The list of tasks we want to save. + * @return A message indicating that the user has exited. */ public String parseExit(Storage storage, TaskList taskList) { storage.saveFile(taskList); @@ -26,8 +30,11 @@ public String parseExit(Storage storage, TaskList taskList) { return ui.showExitMessage(); } - /* + /** * A method to parse the user command 'list'. + * + * @param taskList The list of tasks that we want to output. + * @return A string representing the output. */ public String parseList(TaskList taskList) { int size = taskList.size(); @@ -41,8 +48,11 @@ public String parseList(TaskList taskList) { return text; } - /* + /** * A method to parse the user command 'clear'. + * + * @param taskList The list of tasks that we want to clear. + * @return A string representing the output. */ public String parseClear(TaskList taskList) { taskList.clearTasks(); @@ -50,8 +60,12 @@ public String parseClear(TaskList taskList) { return ui.showClearMessage(); } - /* + /** * A method to parse the user command 'mark'. + * + * @param input A string representing the input. + * @param taskList The list of tasks that we want to mark a task. + * @return A string representing the output. */ public String parseMark(String input, TaskList taskList) { try { @@ -67,8 +81,12 @@ public String parseMark(String input, TaskList taskList) { } } - /* + /** * A method to parse the user command 'unmark'. + * + * @param input A string representing the input. + * @param taskList The list of tasks that we want to unmark a task. + * @return A string representing the output. */ public String parseUnmark(String input, TaskList taskList) { try { @@ -84,8 +102,12 @@ public String parseUnmark(String input, TaskList taskList) { } } - /* + /** * A method to parse the new deadline task. + * + * @param input A string representing the input. + * @param taskList The list of tasks that we want to add a task to. + * @return A string representing the output. */ public String parseDeadline(String input, TaskList taskList) { try { @@ -105,8 +127,12 @@ public String parseDeadline(String input, TaskList taskList) { } } - /* + /** * A method to parse the new todo task. + * + * @param input A string representing the input. + * @param taskList The list of tasks that we want to add a task to. + * @return A string representing the output. */ public String parseTodo(String input, TaskList taskList) { String taskDescription = input.substring(5); @@ -116,8 +142,10 @@ public String parseTodo(String input, TaskList taskList) { return ui.showTodoMessage(newTask, taskList.size()); } - /* + /** * A method to parse the new event task. + * + * @return A string representing the output. */ public String parseEvent(String input, TaskList taskList) { int fromIndex = input.indexOf("/from "); @@ -132,8 +160,12 @@ public String parseEvent(String input, TaskList taskList) { return ui.showEventMessage(newTask, taskList.size()); } - /* + /** * A method to parse the user command 'delete'. + * + * @param input A string representing the input. + * @param taskList The list of tasks that we want to delete from. + * @return A string representing the output. */ public String parseDelete(String input, TaskList taskList) { int index = Integer.parseInt(input.substring(7)) - 1; @@ -143,8 +175,12 @@ public String parseDelete(String input, TaskList taskList) { return ui.showDeleteMessage(task, taskList.size()); } - /* + /** * A method to parse the user command 'find'. + * + * @param input A string represnting the input. + * @param taskList The list of tasks that we want to find from. + * @return A string representing the output. */ public String parseFind(String input, TaskList taskList) { String keyword = input.substring(5).trim(); diff --git a/src/main/java/bob/Storage.java b/src/main/java/bob/Storage.java index 688f6e3937..00afec2d0a 100644 --- a/src/main/java/bob/Storage.java +++ b/src/main/java/bob/Storage.java @@ -4,7 +4,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -/* +/** * A class for saving and loading files from storage. */ public class Storage { @@ -17,7 +17,7 @@ public Storage(String filePath) { this.filePath = filePath; } - /* + /** * A method to load tasks from the specified file path. * * @return A TaskList parsed from the save file. @@ -86,7 +86,7 @@ else if (taskType.equals("E")) { return taskList; } - /* + /** * A method to save the current tasks. * * @param taskList An ArrayList of the current tasks. diff --git a/src/main/java/bob/Task.java b/src/main/java/bob/Task.java index fc9000f050..9a48e1cbdb 100644 --- a/src/main/java/bob/Task.java +++ b/src/main/java/bob/Task.java @@ -2,14 +2,14 @@ import java.util.Objects; -/* +/** * This class represents a task we want to record. */ class Task { private final String description; private boolean isDone; - /* + /** * A constructor that depicts a new task. */ public Task(String description) { @@ -17,21 +17,21 @@ public Task(String description) { this.isDone = false; } - /* + /** * A method that marks a task as done. */ public void markAsDone() { this.isDone = true; } - /* + /** * A method that will undo the mark on a task. */ public void markAsUndone() { this.isDone = false; } - /* + /** * A method that returns the isDone boolean. * * @return A boolean depending on whether the task is done. @@ -40,7 +40,7 @@ public boolean getIsDone() { return this.isDone; } - /* + /** * A method that returns the description. * * @return A string of the task description. @@ -49,7 +49,7 @@ public String getDescription() { return this.description; } - /* + /** * A method that returns the task status as a string. * * @return A check-box followed by the description of the task. @@ -59,7 +59,7 @@ public String toString() { return "[" + (isDone ? "X" : " ") + "] " + description; } - /* + /** * A method to compare the contents of two task objects. * * @param o The object to compare to. diff --git a/src/main/java/bob/TaskList.java b/src/main/java/bob/TaskList.java index 22667d78fa..a1a2d5cc3d 100644 --- a/src/main/java/bob/TaskList.java +++ b/src/main/java/bob/TaskList.java @@ -3,62 +3,62 @@ import java.util.ArrayList; import java.util.Iterator; -/* +/** * A class that encapsulates a list of tasks. */ public class TaskList implements Iterable { private final ArrayList tasks; - /* + /** * A constructor that creates a new task list. */ public TaskList() { this.tasks = new ArrayList<>(); } - /* + /** * A constructor that creates a new task list out of the given array list. */ public TaskList(ArrayList arrayList) { this.tasks = arrayList; } - /* + /** * This method returns the size of the TaskList. */ public int size() { return tasks.size(); } - /* + /** * This method adds a task into the list. */ public void addTask(Task task) { tasks.add(task); } - /* + /** * This method removes a task from the list. */ public void removeTask(int index) { tasks.remove(index); } - /* + /** * This method retrieves the task from the specified index. */ public Task getTask(int index) { return tasks.get(index); } - /* + /** * This method clears all tasks from the list. */ public void clearTasks() { tasks.clear(); } - /* + /** * This method checks if the list is empty. * * @return A boolean representing whether the task list is empty. @@ -67,7 +67,7 @@ public boolean isEmpty() { return tasks.isEmpty(); } - /* + /** * An Iterator method that goes through each task in the list. */ @Override @@ -75,7 +75,7 @@ public Iterator iterator() { return tasks.iterator(); } - /* + /** * A method to check if the contents of the task lists are equal. * * @param o The object that you want to compare. diff --git a/src/main/java/bob/ToDo.java b/src/main/java/bob/ToDo.java index e85131b3bd..4fb7ab250d 100644 --- a/src/main/java/bob/ToDo.java +++ b/src/main/java/bob/ToDo.java @@ -1,17 +1,17 @@ package bob; -/* +/** * This class represents a ToDo that can be recorded in the tasklist. */ class ToDo extends Task { - /* + /** * A constructor for creating a new todo task. */ public ToDo(String description) { super(description); } - /* + /** * A method that returns the task description. * * @return A label [T] and a check-box followed by the description of the task. diff --git a/src/main/java/bob/Ui.java b/src/main/java/bob/Ui.java index 029552629a..3cac5e6c3e 100644 --- a/src/main/java/bob/Ui.java +++ b/src/main/java/bob/Ui.java @@ -1,18 +1,20 @@ package bob; -/* +/** * A class that deals with the interactions with the user. */ public class Ui { - /* + /** * An empty constructor since there is nothing to initialise. */ public Ui() { // Do nothing } - /* + /** * A method to greet the user. + * + * @return A string representing the output. */ public String showGreetMessage() { String greet = "Hello! I'm Bob.\n" @@ -21,52 +23,70 @@ public String showGreetMessage() { return greet; } - /* + /** * A method to respond to the user when prompted for 'list' command. + * + * @return A string representing the output. */ public String showTasksInListMessage() { return "Here are the tasks in your list:\n"; } - /* + /** * A method to respond to the user when prompted for 'clear' command. + * + * @return A string representing the output. */ public String showClearMessage() { return "Your tasks have been cleared."; } - /* + /** * A method to respond when the user has an incomplete entry. + * + * @return A string representing the output. */ public String showIncompleteEntryMessage() { return "Your entry is incomplete!"; } - /* + /** * A method that indicates that a task has been marked as done. + * + * @param task The task we want to mark. + * @return A string representing the output. */ public String showMarkTaskMessage(Task task) { return "Nice! I've marked this task as done:\n" + " " + task; } - /* + /** * A method that indicates that a task has been unmarked. + * + * @param task The task we want to unmark. + * @return A string representing the output. */ public String showUnmarkTaskMessage(Task task) { return "OK, I've marked this task as not done yet:\n" + task; } - /* + /** * A method to indicate that no such task exists. + * + * @return A string representing the output. */ public String showNoSuchTaskMessage() { return "There exists no such task."; } - /* + /** * A method that prints a message when a deadline is added. + * + * @param task The deadline task we want to add. + * @param size The size of the task list. + * @return A string representing the output. */ public String showDeadlineMessage(Task task, int size) { return "Got it. I've added this task:\n" @@ -74,8 +94,12 @@ public String showDeadlineMessage(Task task, int size) { + "Now you have " + size + " tasks in the list."; } - /* + /** * A method that prints a message when a todo is added. + * + * @param task The todo task we want to add. + * @param size The size of the task list. + * @return A string representing the output. */ public String showTodoMessage(Task task, int size) { return "Got it. I've added this task:\n" @@ -83,8 +107,12 @@ public String showTodoMessage(Task task, int size) { + "Now you have " + size + " tasks in the list."; } - /* + /** * A method that prints a message when an event is added. + * + * @param task The event task we want to add. + * @param size The size of the task list. + * @return A string representing the output. */ public String showEventMessage(Task task, int size) { return "Got it. I've added this task:\n" @@ -92,8 +120,12 @@ public String showEventMessage(Task task, int size) { + "Now you have " + size + " tasks in the list."; } - /* + /** * A method that prints a message when a task is deleted. + * + * @param task The task we want to delete. + * @param size The size of the taskList. + * @return A string representing the output. */ public String showDeleteMessage(Task task, int size) { return "Noted. I've removed this task:\n" @@ -101,36 +133,46 @@ public String showDeleteMessage(Task task, int size) { + "Now you have " + size + " tasks in the list."; } - /* + /** * A method that shows a message when the command is unknown. + * + * @return A string representing the output. */ public String showUnknownCommandMessage() { return "Bob knows not what that means."; } - /* + /** * A method that prints an error message when the date/time input is in the wrong format. + * + * @return A string representing the output. */ public String showDateTimeFormatErrorMessage() { return "Your date/time input format should be yyyy-MM-dd HHmm"; } - /* + /** * A method to display an exit message when exiting the chatbot. + * + * @return A string representing the output. */ public String showExitMessage() { return "Bye. Hope to see you again soon!"; } - /* + /** * A method to display a message that no tasks were found from 'find'. + * + * @return A string representing the output. */ public String showNoMatchingTasksMessage() { return "No tasks were found containing the specified keyword."; } - /* + /** * A method to display a message for the tasks found in the task list from 'find'. + * + * @return A string representing the output. */ public String showMatchingTasksInListMessage() { return "Here are the matching tasks in your list:\n";