diff --git a/src/main/java/duke/command/AddCommand.java b/src/main/java/duke/command/AddCommand.java index 3fef2ba34d..db3e95f405 100644 --- a/src/main/java/duke/command/AddCommand.java +++ b/src/main/java/duke/command/AddCommand.java @@ -2,18 +2,33 @@ import duke.task.Task; import duke.functionality.TaskList; - +/** + * Represents the add command. A AddCommand object corresponds to adding that specified task + * to the taskList in the TaskList class. + */ public class AddCommand extends Command { + /** + * Constructor of AddCommand class. + * @param t task object created from user input. + */ public AddCommand(Task t){ super(t, null); } + /** + * Returns nothing, but adds the specified task in the taskList in TaskList class. + * @param tasks an object of TaskList, used to access public methods in TaskList class. + */ @Override public void execute(TaskList tasks) { tasks.addToList(super.task); } + /** + * Returns false as the Command is not an ExitCommand. + * @return false. + */ @Override public boolean isExit() { return false; diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java index 327ab9ef8a..93431a5d56 100644 --- a/src/main/java/duke/command/Command.java +++ b/src/main/java/duke/command/Command.java @@ -3,16 +3,32 @@ import duke.task.Task; import duke.functionality.TaskList; +/** + * Represents the commands inputted by a user. The Command class cannot be instantiated as it is an abstract class. + */ public abstract class Command{ protected Task task; protected Integer index; + /** + * Constructor of Command class. + * @param t task object created from user input. + * @param number an indicator to the index of the taskList in TaskList class. + */ public Command(Task t, Integer number) { this.task = t; this.index = number; } + /** + * Returns nothing, but used to execute the respective methods in TaskList class. + * @param tasks an object of TaskList, used to access public methods in TaskList class. + */ public abstract void execute(TaskList tasks); + /** + * Returns a boolean depending on the input command of the user. + * @return returns true if Command is an ExitCommand, eg: "bye". Else returns false. + */ public abstract boolean isExit(); } diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java index 9248b37d17..6bfda2d1fd 100644 --- a/src/main/java/duke/command/DeleteCommand.java +++ b/src/main/java/duke/command/DeleteCommand.java @@ -2,18 +2,34 @@ import duke.functionality.TaskList; +/** + * Represents the delete command. A DeleteCommand object corresponds to deleting that specified task + * to the taskList in the TaskList class. + */ public class DeleteCommand extends Command { + /** + * Constructor for DeleteCommand class. + * @param number an indicator to the index of the taskList in TaskList class. + */ public DeleteCommand(Integer number) { super(null, number); } + /** + * Returns nothing, but deletes the specified task in the taskList in TaskList class. + * @param tasks an object of TaskList, used to access public methods in TaskList class. + */ @Override public void execute(TaskList tasks) { tasks.deleteTask(super.index); } + /** + * Returns false as the Command is not an ExitCommand. + * @return false. + */ @Override public boolean isExit() { return false; diff --git a/src/main/java/duke/command/ExitCommand.java b/src/main/java/duke/command/ExitCommand.java index 91e444b320..e4e853ed54 100644 --- a/src/main/java/duke/command/ExitCommand.java +++ b/src/main/java/duke/command/ExitCommand.java @@ -2,15 +2,29 @@ import duke.functionality.TaskList; +/** + * Represents the exit command. A ExitCommand object corresponds to exiting the Duke program. + */ public class ExitCommand extends Command{ + /** + * Constructor for ExitCommand class. + */ public ExitCommand() { super(null, null); } + /** + * Returns nothing & does not execute anything. + * @param tasks an object of TaskList, used to access public methods in TaskList class. + */ @Override public void execute(TaskList tasks) { } + /** + * Returns true as the Command is an ExitCommand. + * @return true. + */ @Override public boolean isExit() { return true; diff --git a/src/main/java/duke/command/MarkCommand.java b/src/main/java/duke/command/MarkCommand.java index d58c992e75..97c47812d8 100644 --- a/src/main/java/duke/command/MarkCommand.java +++ b/src/main/java/duke/command/MarkCommand.java @@ -2,17 +2,32 @@ import duke.functionality.TaskList; +/** + * Represents the mark command. A MarkCommand object allows users to set the corresponding task as done. + */ public class MarkCommand extends Command { + /** + * Constructor for MarkCommand class. + * @param number an indicator to the index of the taskList in TaskList class. + */ public MarkCommand(Integer number) { super(null, number); } + /** + * Returns nothing, but marks the corresponding task in the taskList in TaskList class as done. + * @param tasks an object of TaskList, used to access public methods in TaskList class. + */ @Override public void execute(TaskList tasks) { tasks.markTask(super.index); } + /** + * Returns false as the Command is not an ExitCommand. + * @return false. + */ @Override public boolean isExit() { return false; diff --git a/src/main/java/duke/command/PrintCommand.java b/src/main/java/duke/command/PrintCommand.java index d6a6f85be8..a8540241fc 100644 --- a/src/main/java/duke/command/PrintCommand.java +++ b/src/main/java/duke/command/PrintCommand.java @@ -2,17 +2,31 @@ import duke.functionality.TaskList; +/** + * Represents the print command. A PrintCommand object allows users to see all task in Duke TaskBot. + */ public class PrintCommand extends Command{ + /** + * Constructor for PrintCommand class. + */ public PrintCommand() { super(null, null); } + /** + * Returns nothing, but prints out all the task in the taskList in TaskList class. + * @param tasks an object of TaskList, used to access public methods in TaskList class. + */ @Override public void execute(TaskList tasks) { tasks.printList(); } + /** + * Returns false as the Command is not an ExitCommand. + * @return false. + */ @Override public boolean isExit() { return false; diff --git a/src/main/java/duke/command/UnmarkCommand.java b/src/main/java/duke/command/UnmarkCommand.java index bfc5d3614c..a39c15decb 100644 --- a/src/main/java/duke/command/UnmarkCommand.java +++ b/src/main/java/duke/command/UnmarkCommand.java @@ -1,18 +1,33 @@ package duke.command; import duke.functionality.TaskList; - +/** + * Represents the unmark command. A UnmarkCommand object allows users to set the corresponding task as + * not done. + */ public class UnmarkCommand extends Command{ + /** + * Constructor for the UnmarkCommand class. + * @param number an indicator to the index of the taskList in TaskList class. + */ public UnmarkCommand(Integer number) { super(null, number); } + /** + * Returns nothing, but marks the corresponding task in the taskList in TaskList class as not done. + * @param tasks an object of TaskList, used to access public methods in TaskList class. + */ @Override public void execute(TaskList tasks) { tasks.unMarkTask(super.index); } + /** + * Returns false as the Command is not an ExitCommand. + * @return false. + */ @Override public boolean isExit() { return false; diff --git a/src/main/java/duke/exception/BlankCommandException.java b/src/main/java/duke/exception/BlankCommandException.java index dce6f93f39..34924c6c2f 100644 --- a/src/main/java/duke/exception/BlankCommandException.java +++ b/src/main/java/duke/exception/BlankCommandException.java @@ -1,7 +1,14 @@ package duke.exception; +/** + * Represents the BlankCommandException the Duke program would handle. A BlankCommandException + * object corresponds to a blank command inputted by a user. Eg, " ". + */ public class BlankCommandException extends DukeException { + /** + * Constructor for BlankCommandException class. + */ public BlankCommandException() { super("OOPS!!! I'm sorry, but I do not accept empty commands! :-("); } diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java index 8ef4205657..f875022086 100644 --- a/src/main/java/duke/exception/DukeException.java +++ b/src/main/java/duke/exception/DukeException.java @@ -1,6 +1,15 @@ package duke.exception; +/** + * Represents the Exceptions the Duke program would handle. A DukeException object corresponds + * to the exceptions specified and handled by Duke. + */ public class DukeException extends Exception{ + + /** + * Constructor for DukeException class. + * @param description the error message provided for the exception. + */ public DukeException(String description) { super(description); } diff --git a/src/main/java/duke/exception/IncompleteCommandException.java b/src/main/java/duke/exception/IncompleteCommandException.java index 29cb4a3fc6..1ebae15f84 100644 --- a/src/main/java/duke/exception/IncompleteCommandException.java +++ b/src/main/java/duke/exception/IncompleteCommandException.java @@ -1,6 +1,15 @@ package duke.exception; +/** + * Represents the IncompleteCommandException the Duke program would handle. A IncompleteCommandException + * object corresponds to a incomplete command inputted by a user. Eg, event sleep /at. + */ public class IncompleteCommandException extends DukeException { + + /** + * Constructor for IncompleteCommandException class. + * @param command the respective task the user has inputted eg,todo/event/deadline. + */ public IncompleteCommandException(String command) { super("OOPS!!! The description of a " + command + " cannot be empty."); } diff --git a/src/main/java/duke/exception/InvalidCommandException.java b/src/main/java/duke/exception/InvalidCommandException.java index 8d1d3a5f24..63f4fd05a8 100644 --- a/src/main/java/duke/exception/InvalidCommandException.java +++ b/src/main/java/duke/exception/InvalidCommandException.java @@ -1,6 +1,14 @@ package duke.exception; +/** + * Represents the InvalidCommandException the Duke program would handle. A InvalidCommandException + * object corresponds to an invalid command inputted by a user. Eg, blah. + */ public class InvalidCommandException extends DukeException { + + /** + * Constructor for InvalidCommandException class. + */ public InvalidCommandException() { super("OOPS!!! I'm sorry, but I don't know what that means :-("); } diff --git a/src/main/java/duke/functionality/Parser.java b/src/main/java/duke/functionality/Parser.java index b41aecfee5..cba4717b45 100644 --- a/src/main/java/duke/functionality/Parser.java +++ b/src/main/java/duke/functionality/Parser.java @@ -20,6 +20,10 @@ import duke.exception.IncompleteCommandException; import duke.exception.InvalidCommandException; +/** + * Represents the Parsing capabilities of the Duke project. A Parse object corresponds + * to the actions taken to parse and format user inputs. + */ public class Parser { private static final int EVENT_OFFSET = 5; @@ -27,30 +31,56 @@ public class Parser { private static final int DEADLINE_OFFSET = 8; private static final int INPUT_OFFSET = 3; + /** + * Returns the formatted date. + * @param input date specified by user input. Eg, "2020-06-06". + * @return formatted date. + */ public static LocalDate formatDate(String input){ DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "yyyy-MM-dd"); LocalDate date = LocalDate.parse(input, dtf); return date; } + /** + * Returns the formatted time. + * @param input time specified by user input. Eg, "1800". + * @return formatted time. + */ public static LocalTime formatTime(String input) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "HHmm"); LocalTime time = LocalTime.parse(input, dtf); return time; } + /** + * Returns the date. + * @param input formatted date. Eg, "2020-06-06". + * @return date but as a String. + */ public static String dateToString(LocalDate input) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "yyyy-MM-dd"); String date = input.format(dtf); return date; } + /** + * Returns the time. + * @param input formatted time Eg, "1800". + * @return time but as a String. + */ public static String timeToString(LocalTime input) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern( "HHmm"); String time = input.format(dtf); return time; } + /** + * Returns the respective command from user input. + * @param input user input. Eg, "todo run". + * @return the command. + * @throws DukeException when user input for date and time are not of the correct form. + */ public static Command parse(String input) throws DukeException { String[] inputSplit = input.split(" "); //split input by space String command = inputSplit[0]; diff --git a/src/main/java/duke/functionality/Storage.java b/src/main/java/duke/functionality/Storage.java index 7080567cc1..d99e572c81 100644 --- a/src/main/java/duke/functionality/Storage.java +++ b/src/main/java/duke/functionality/Storage.java @@ -12,20 +12,38 @@ import java.io.FileWriter; import java.io.IOException; +/** + * Represents the Storage capabilities of the Duke project. A Storage object corresponds + * to the actions available to write and read data/task. + */ public class Storage { protected static String pwd; protected static String path; + /** + * Constructor for Storage class. + * @param pwd user's current working directory. + * @param path path to "/data/TaskData.txt". + */ public Storage(String pwd, String path){ Storage.pwd = pwd; Storage.path = path; } + /** + * Returns nothing, but stores the specified task into the taskList in TaskList class. + * @param t the task created in Parser class. + */ public static void storeToList(Task t) { //same as addToList but no printing TaskList.taskList.add(t); TaskList.numOfTask++; } + /** + * Returns nothing, but stores all task into the text file specified by path. + * @param path path to "/data/TaskData.txt". + * @throws IOException if the text file is missing. + */ public static void writeToFile(String path) throws IOException { FileWriter fw = new FileWriter(path); for(int i = 0; i < TaskList.numOfTask; i++) { @@ -36,6 +54,9 @@ public static void writeToFile(String path) throws IOException { fw.close(); } + /** + * Returns nothing, but calls writeToFile to update the text file. + */ public static void updateTextFile() { try { writeToFile(Storage.pwd + Storage.path); @@ -44,6 +65,11 @@ public static void updateTextFile() { } } + /** + * Returns nothing, but reads the input from the specified file and stores them in the taskList in TaskList class. + * @param f the text file that stores all tasks. + * @throws FileNotFoundException if the file is missing. + */ public static void readFileDataAndStoreInList(File f) throws FileNotFoundException { Scanner sc = new Scanner(f); while ((sc.hasNextLine())) { @@ -75,6 +101,11 @@ public static void readFileDataAndStoreInList(File f) throws FileNotFoundExcepti } } + /** + * Returns a crafted output to be stored in the text file. + * @param t the task created in Parser class. + * @return crafted output. + */ public static String craftOutput(Task t) { String output = ""; String doneIcon = t.getStatusIcon(); @@ -106,6 +137,10 @@ public static String craftOutput(Task t) { return output; } + /** + * Returns nothing, but loads all tasks from the specified path. + * @throws IOException if the file is missing. + */ public void load() throws IOException { File directory = new File(pwd + "/data"); File inputFile = new File(pwd + path); diff --git a/src/main/java/duke/functionality/TaskList.java b/src/main/java/duke/functionality/TaskList.java index ac4995fadb..852c39019a 100644 --- a/src/main/java/duke/functionality/TaskList.java +++ b/src/main/java/duke/functionality/TaskList.java @@ -3,13 +3,23 @@ import java.util.ArrayList; import duke.task.Task; - +/** + * Represents the Tasks of the Duke project. A TaskList object corresponds + * to the actions available on a Task object. + */ public class TaskList { protected static ArrayList taskList = new ArrayList<>(); protected static int numOfTask = 0; + /** + * Default constructor of TaskList class. + */ public TaskList() { } + /** + * Returns nothing, but deletes the task specified. + * @param taskNum an indicator to the index of taskList. + */ public void deleteTask(int taskNum) { String message = "Noted. I've removed this task:\n"; int actualTaskNum = taskNum - 1; @@ -20,6 +30,10 @@ public void deleteTask(int taskNum) { System.out.println("Now you have " + numOfTask + " tasks in the list."); } + /** + * Returns nothing, but marks the task specified as done. + * @param taskNum an indicator to the index of taskList. + */ public void markTask(int taskNum) { String message = "Nice! I've marked this task as done:\n" ; int actualTaskNum = taskNum - 1; //minus 1 as list index is from 0 @@ -29,6 +43,10 @@ public void markTask(int taskNum) { System.out.println(message + t.toString()); } + /** + * Returns nothing, but marks the task specified as not done. + * @param taskNum an indicator to the index of taskList. + */ public void unMarkTask(int taskNum) { String message = "OK, I've marked this task as not done yet:\n"; int actualTaskNum = taskNum - 1; @@ -38,6 +56,9 @@ public void unMarkTask(int taskNum) { System.out.println(message + t.toString()); } + /** + * Returns nothing, but prints out all task in taskList. + */ public void printList(){ String message = "Here are the tasks in your list:"; System.out.println(message); @@ -48,6 +69,10 @@ public void printList(){ } } + /** + * Returns nothing, but adds the task specified into the taskList. + * @param t the task created in Parser class. + */ public void addToList(Task t) { String message = "Got it. I've added this task:\n"; taskList.add(t); diff --git a/src/main/java/duke/functionality/Ui.java b/src/main/java/duke/functionality/Ui.java index adf23596b4..1ea19e32b9 100644 --- a/src/main/java/duke/functionality/Ui.java +++ b/src/main/java/duke/functionality/Ui.java @@ -4,25 +4,45 @@ import java.util.Scanner; - +/** + * Represents the User Interface of the Duke project. A Ui object corresponds + * to all user interface displays. Such as the messages. + */ public class Ui { private String greeting = "Hello! I'm TaskJamie\nWhat can i do for you?"; private String ending = "Bye. Hope to see you again soon!"; + /** + * Returns nothing, but prints out the greeting message of Duke TaskBot. + */ public void showGreeting() { System.out.println(greeting); } + /** + * Returns nothing, but prints out the leaving message of Duke TaskBot. + */ public void showEnding() { System.out.println(ending); } + /** + * Returns nothing, but prints out the error messages caught by Duke TaskBot. + */ public void showError(String error) { System.out.println(error); } + /** + * Returns nothing, but prints out the error messages when loading in the text file. + */ public void showLoadingError(String error) { System.out.println(error); } + /** + * Returns a full command gotten from user input. + * @return string containing full command. + * @throws BlankCommandException if user inputs nothing. Eg, " ". + */ public String readCommand() throws BlankCommandException { Scanner sc = new Scanner(System.in); String input; diff --git a/src/main/java/duke/main/Duke.java b/src/main/java/duke/main/Duke.java index 624524148e..240a5ff9fe 100644 --- a/src/main/java/duke/main/Duke.java +++ b/src/main/java/duke/main/Duke.java @@ -9,12 +9,21 @@ import duke.functionality.Ui; import duke.exception.DukeException; +/** + * Represents the starting point of the Duke project. A Duke object corresponds + * to a TaskBot that helps keep tracks of all tasks inputted by a user. + */ public class Duke { private final Storage storage; private TaskList tasks; private final Ui ui; + /** + * Constructor for Duke class. + * @param pwd user's current working directory. + * @param filePath path to "/data/TaskData.txt". + */ public Duke(String pwd, String filePath) { this.ui = new Ui(); this.storage = new Storage(pwd, filePath); @@ -26,6 +35,10 @@ public Duke(String pwd, String filePath) { } } + /** + * This method is used to start the execution of the TaskBot. This method would continually ask users for input + * until the user enters the ExitCommand. Eg, "Bye". + */ public void run() { this.ui.showGreeting(); boolean isExit = false; @@ -42,6 +55,10 @@ public void run() { ui.showEnding(); } + /** + * This is the main method which makes use of run method. + * @param args unused. + */ public static void main(String[] args) { String home = System.getProperty("user.home"); new Duke(home,"/data/TaskData.txt").run(); diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index f742242c3a..6f61a06884 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -4,10 +4,20 @@ import java.time.LocalTime; import java.time.format.DateTimeFormatter; +/** + * Represents the deadline a user would create. A Deadline object is a subclass of the Task class + * and corresponds to a deadline input by a user. + */ public class Deadline extends Task { protected LocalTime time; protected LocalDate date; + /** + * Constructor for the Deadline class. + * @param description information about the deadline. + * @param date date details about the deadline. + * @param time time details about the deadline. + */ public Deadline(String description, LocalDate date, LocalTime time) { super(description); this.time = time; @@ -22,6 +32,11 @@ public LocalDate getDate(){ return this.date; } + /** + * Returns the string representation of a deadline. + * @return a string representation of the deadline, consisting of its description + * and formatted date and time. + */ @Override public String toString() { return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM dd yyyy")) diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 86f4f1a12d..d7af77f0d1 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -5,11 +5,22 @@ import java.time.LocalTime; import java.time.format.DateTimeFormatter; +/** + * Represents the event a user would create. A Event object is a subclass of the Task class + * and corresponds to an event inputted by a user. + */ public class Event extends Task { protected LocalDate date; protected LocalTime startTime; protected LocalTime endTime; + /** + * Constructor for the Event class. + * @param description information about the event. + * @param date date details about the deadline. + * @param startTime starting time of the deadline. + * @param endTime ending time of the deadline. + */ public Event(String description, LocalDate date, LocalTime startTime, LocalTime endTime) { super(description); this.date = date; @@ -29,11 +40,15 @@ public LocalTime getEndTime(){ return this.endTime; } + /** + * Returns the string representation of an event. + * @return a string representation of the event, consisting of its description, formatted date, + * starting time and ending time. + */ @Override public String toString() { return "[E]" + super.toString() + " (at: " + date.format(DateTimeFormatter.ofPattern("MMM dd yyyy")) + " " + startTime.format(DateTimeFormatter.ofPattern("h:mm a")) + " to" + " " + endTime.format(DateTimeFormatter.ofPattern("h:mm a")) + ")"; } - } diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index d58b9aeab0..8b91fe670a 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,9 +1,17 @@ package duke.task; +/** + * Represents the Tasks a user could create. A Task object would correspond to a task + * inputted by a user either a Todo, Deadline or Event. + */ public class Task { protected String description; protected boolean isDone; + /** + * Constructor for Task class. + * @param description information about the task. + */ public Task(String description) { this.description = description; this.isDone = false; @@ -29,6 +37,10 @@ public String getDescription(){ return this.description; } + /** + * Returns the string representation of the task. + * @return a string representation of the task, consisting of its description and whether its done or not. + */ @Override public String toString() { return "[" + getStatusIcon() + "] " + getDescription(); diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index 1dc39b7f66..0a42277a16 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -1,10 +1,23 @@ package duke.task; +/** + * Represents the todo task a user would create. A Todo object is a subclass of the Task class + * and corresponds to a todo inputted by a user. + */ public class Todo extends Task { + + /** + * Constructor for the Todo class. + * @param description information about the todo task. + */ public Todo(String description) { super(description); } + /** + * Returns the string representation of a todo. + * @return a string representation of the todo, consisting of its description. + */ @Override public String toString() { return "[T]" + super.toString();