diff --git a/src/main/java/ByeRequest.java b/src/main/java/ByeRequest.java deleted file mode 100644 index 0fa80efd4a..0000000000 --- a/src/main/java/ByeRequest.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * ByeRequest represents a request from the user to stop the application. - */ -public class ByeRequest extends Request { - /** - * Gets the Action the ByeRequest requests to execute. - * @return The Action to be executed. - */ - @Override - public Action action() { - return new GoodbyeUser(); - } -} diff --git a/src/main/java/CompleteTask.java b/src/main/java/CompleteTask.java deleted file mode 100644 index c2cca16e46..0000000000 --- a/src/main/java/CompleteTask.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * CompleteTask is an Action that marks a Task as done. - */ -public class CompleteTask implements Action { - private final Task task; - - /** - * Creates an Action CompleteTask that marks a Task as done. - * @param task The Task to be marked as done. - */ - public CompleteTask(Task task) { - this.task = task; - } - - /** - * Marks the Task as done. - * @return The Response. - */ - @Override - public Response execute() { - this.task.isDone = true; - return this.respond(); - } - - /** - * Returns the Response for marking the Task as done. - * @return The Response. - */ - private Response respond() { - return new Response(new String[]{ - "Nice! I've marked this task as done:", - String.format(" %s", this.task.toString()), - }); - } -} diff --git a/src/main/java/DeleteTask.java b/src/main/java/DeleteTask.java deleted file mode 100644 index c8c22229f5..0000000000 --- a/src/main/java/DeleteTask.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * DeleteTask is an Action that deletes a Task from a TaskCollection. - */ -public class DeleteTask implements Action { - private final int taskId; - private final TaskCollection taskCollection; - - /** - * Creates an Action DeleteTask that deletes a Task from a TaskCollection. - * @param taskId The identifier of the Task to be deleted. - * @param taskCollection The TaskCollection to delete the Task from. - */ - public DeleteTask(int taskId, TaskCollection taskCollection) { - this.taskId = taskId; - this.taskCollection = taskCollection; - } - - /** - * Deletes the Task from the TaskCollection. - * @return The Response. - */ - @Override - public Response execute() { - Task deletedTask = this.taskCollection.delete(this.taskId); - return this.respond(deletedTask); - } - - /** - * Returns the Response for successfully adding the Task to the TaskCollection. - * @param deletedTask The Task that was deleted. - * @return The Response. - */ - private Response respond(Task deletedTask) { - return new Response(new String[]{ - "Noted. I've removed this task:", - String.format(" %s", deletedTask.toString()), - String.format("Now you have %d tasks in the list.", this.taskCollection.size()) - }); - } -} diff --git a/src/main/java/ListRequest.java b/src/main/java/ListRequest.java deleted file mode 100644 index 3a987cf1bc..0000000000 --- a/src/main/java/ListRequest.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * ListRequest represents a request from the user to list all the Tasks in the application. - */ -public class ListRequest extends TaskCollectionRequest { - /** - * Creates a ListRequest. - * @param taskCollection The target TaskCollection. - */ - protected ListRequest(TaskCollection taskCollection) { - super(taskCollection); - } - - /** - * Gets the Action the ListRequest requests to execute. - * @return The Action to be executed. - */ - @Override - public Action action() { - return new ListTasks(this.taskCollection); - } -} diff --git a/src/main/java/ListTasks.java b/src/main/java/ListTasks.java deleted file mode 100644 index b0eb7251e2..0000000000 --- a/src/main/java/ListTasks.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * ListTasks is an Action that lists the Tasks in a TaskCollection. - */ -public class ListTasks implements Action { - private final TaskCollection taskCollection; - - /** - * Creates an Action ListTasks that lists the Tasks in a TaskCollection. - * @param taskCollection The TaskCollection. - */ - public ListTasks(TaskCollection taskCollection) { - this.taskCollection = taskCollection; - } - - /** - * Lists all the Tasks in the TaskCollection. - * @return The Response. - */ - @Override - public Response execute() { - return this.respond(); - } - - /** - * Returns the Response for listing all the Tasks in the TaskCollection. - * @return The Response. - */ - private Response respond() { - return new Response(new String[]{ - "Here are the tasks in your list:", - this.taskCollection.toString(), - }); - } -} diff --git a/src/main/java/TaskCollectionRequest.java b/src/main/java/TaskCollectionRequest.java deleted file mode 100644 index 791fa9e4f6..0000000000 --- a/src/main/java/TaskCollectionRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * A TaskCollectionRequest represents a Request made to a TaskCollection. - */ -public abstract class TaskCollectionRequest extends Request { - protected TaskCollection taskCollection; - - /** - * Creates a TaskCollectionRequest to a specified Collection. - * @param taskCollection The Target TaskCollection. - */ - protected TaskCollectionRequest(TaskCollection taskCollection) { - this.taskCollection = taskCollection; - } -} diff --git a/src/main/java/TaskType.java b/src/main/java/TaskType.java deleted file mode 100644 index 70f9c9e7e9..0000000000 --- a/src/main/java/TaskType.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * A TaskType represents a type of Task in the application. - */ -public enum TaskType { - DEADLINE("D"), - EVENT("E"), - TODO("T"); - - /** - * The name of the Task. - */ - private final String name; - - /** - * Creates a TaskType with the specified name. - * @param name Name of the TaskType. - */ - TaskType(String name) { - this.name = name; - } - - /** - * Gets the String representation of the TaskType. - * @return The String representation of the TaskType - */ - @Override - public String toString() { - return this.name; - } - - /** - * Parse the input String into an equivalent TaskType. - * @return The equivalent TaskType. - */ - public static TaskType parse(String string) { - for (TaskType taskType : TaskType.values()) { - if (taskType.name.equals(string)) { - return taskType; - } - } - - throw new RuntimeException(String.format("Invalid TaskType string %s.", string)); - } -} diff --git a/src/main/java/UserException.java b/src/main/java/UserException.java deleted file mode 100644 index d306047d35..0000000000 --- a/src/main/java/UserException.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.lang.Exception; - -/** - * A UserException represents an Exception thrown because of an invalid input by the User. - */ -public class UserException extends Exception { - private final String message; - - /** - * Create a UserException with the specified Message. - * @param message The message to be displayed in the Response. - */ - public UserException(String message) { - this.message = message; - } - - /** - * Returns the Response to be printed to the console of this UserException. - */ - public Response toResponse() { - return new Response(new String[]{ "☹ OOPS!!!", this.message }); - } -} diff --git a/src/main/java/Duke.java b/src/main/java/duke/Duke.java similarity index 88% rename from src/main/java/Duke.java rename to src/main/java/duke/Duke.java index 759060b686..9a2d8d2a4e 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,3 +1,12 @@ +package duke; + +import duke.action.Action; +import duke.action.GoodbyeUser; +import duke.action.WelcomeUser; +import duke.exception.UserException; +import duke.request.Request; +import duke.task.TaskCollection; + import java.util.Queue; import java.util.LinkedList; diff --git a/src/main/java/Response.java b/src/main/java/duke/Response.java similarity index 82% rename from src/main/java/Response.java rename to src/main/java/duke/Response.java index 453291dedf..f99d0549ec 100644 --- a/src/main/java/Response.java +++ b/src/main/java/duke/Response.java @@ -1,5 +1,7 @@ +package duke; + /** - * A Response from the application to some user input. + * A duke.Response from the application to some user input. */ public class Response { public static String BASE_INDENT = " "; @@ -18,7 +20,7 @@ public Response() { /** * Creates a response with the specified String message. - * @param message The Response message. + * @param message The duke.Response message. */ public Response(String message) { this(new String[]{ message }); @@ -26,7 +28,7 @@ public Response(String message) { /** * Creates a response with the specified String array. - * @param messages The Response message array. + * @param messages The duke.Response message array. */ public Response(String[] messages) { this.message = String.join(System.lineSeparator(), messages); @@ -43,8 +45,8 @@ public void add(String message) { } /** - * Converts the Response to its String representation. - * @return The String representation of the Response. + * Converts the duke.Response to its String representation. + * @return The String representation of the duke.Response. */ @Override public String toString() { diff --git a/src/main/java/Storage.java b/src/main/java/duke/Storage.java similarity index 80% rename from src/main/java/Storage.java rename to src/main/java/duke/Storage.java index 0a6265d315..12aedf4f90 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/duke/Storage.java @@ -1,3 +1,5 @@ +package duke; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; @@ -5,13 +7,13 @@ import java.util.Scanner; /** - * Storage class is responsible for dealing with loading tasks from file and saving tasks in the file. + * duke.Storage class is responsible for dealing with loading tasks from file and saving tasks in the file. */ public class Storage { private final File file; /** - * Creates a new Storage instance at the specified path. + * Creates a new duke.Storage instance at the specified path. * @param pathname A pathname string */ public Storage(String pathname) { @@ -48,13 +50,13 @@ public String read() { scanner.close(); return contents.toString(); } catch (FileNotFoundException exception) { - throw new RuntimeException("File not found when trying to read file from Storage class."); + throw new RuntimeException("File not found when trying to read file from duke.Storage class."); } } /** - * Writes the specified contents into the Storage file. - * @param contents The String contents to write to the Storage file. + * Writes the specified contents into the duke.Storage file. + * @param contents The String contents to write to the duke.Storage file. */ public void write(String contents) { try { @@ -62,7 +64,7 @@ public void write(String contents) { fileWriter.write(contents); fileWriter.close(); } catch (FileNotFoundException exception) { - throw new RuntimeException("File not found when trying to write to file from Storage class."); + throw new RuntimeException("File not found when trying to write to file from duke.Storage class."); } catch (IOException exception) { throw new RuntimeException( String.format("An I/O exception occurred when trying to write to file %s\n", this.file.getPath()) diff --git a/src/main/java/Ui.java b/src/main/java/duke/Ui.java similarity index 65% rename from src/main/java/Ui.java rename to src/main/java/duke/Ui.java index 8c7d12ab90..ffc92ea70b 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/duke/Ui.java @@ -1,14 +1,16 @@ +package duke; + import java.util.Scanner; /** - * Ui represents the class that deals with interactions with the user + * duke.Ui represents the class that deals with interactions with the user */ public class Ui { Scanner scanner = new Scanner(System.in); /** - * Prints the Response to the console. - * @param response The Response to be printed. + * Prints the duke.Response to the console. + * @param response The duke.Response to be printed. */ public void printResponse(Response response) { System.out.println(response.toString()); diff --git a/src/main/java/Action.java b/src/main/java/duke/action/Action.java similarity index 54% rename from src/main/java/Action.java rename to src/main/java/duke/action/Action.java index 3e51ced49a..f4a2a8a24c 100644 --- a/src/main/java/Action.java +++ b/src/main/java/duke/action/Action.java @@ -1,9 +1,13 @@ +package duke.action; + +import duke.Response; + /** * The Action interface represents an action to be performed in the Duke application. */ public interface Action { /** - * Executes the specified action and returns the resulting Response. + * Executes the specified action and returns the resulting duke.Response. */ Response execute(); } diff --git a/src/main/java/AddTask.java b/src/main/java/duke/action/AddTask.java similarity index 50% rename from src/main/java/AddTask.java rename to src/main/java/duke/action/AddTask.java index 015902a132..deb1d13cda 100644 --- a/src/main/java/AddTask.java +++ b/src/main/java/duke/action/AddTask.java @@ -1,14 +1,20 @@ +package duke.action; + +import duke.Response; +import duke.task.Task; +import duke.task.TaskCollection; + /** - * AddTask is an Action that adds a Task to a TaskCollection. + * duke.action.AddTask is an Action that adds a duke.task.Task to a duke.task.TaskCollection. */ public class AddTask implements Action { private final Task task; private final TaskCollection taskCollection; /** - * Creates an Action AddTask that adds a Task into a TaskCollection. - * @param task The Task to be added. - * @param taskCollection The TaskCollection to add the Task into. + * Creates an Action duke.action.AddTask that adds a duke.task.Task into a duke.task.TaskCollection. + * @param task The duke.task.Task to be added. + * @param taskCollection The duke.task.TaskCollection to add the duke.task.Task into. */ public AddTask(Task task, TaskCollection taskCollection) { this.task = task; @@ -16,8 +22,8 @@ public AddTask(Task task, TaskCollection taskCollection) { } /** - * Adds the Task into the TaskCollection. - * @return The Response. + * Adds the duke.task.Task into the duke.task.TaskCollection. + * @return The duke.Response. */ @Override public Response execute() { @@ -26,8 +32,8 @@ public Response execute() { } /** - * Returns the Response for successfully adding the Task to the TaskCollection. - * @return The Response. + * Returns the duke.Response for successfully adding the duke.task.Task to the duke.task.TaskCollection. + * @return The duke.Response. */ private Response respond() { return new Response(new String[]{ diff --git a/src/main/java/duke/action/CompleteTask.java b/src/main/java/duke/action/CompleteTask.java new file mode 100644 index 0000000000..db9408f81a --- /dev/null +++ b/src/main/java/duke/action/CompleteTask.java @@ -0,0 +1,40 @@ +package duke.action; + +import duke.Response; +import duke.task.Task; + +/** + * duke.action.CompleteTask is an Action that marks a duke.task.Task as done. + */ +public class CompleteTask implements Action { + private final Task task; + + /** + * Creates an Action duke.action.CompleteTask that marks a duke.task.Task as done. + * @param task The duke.task.Task to be marked as done. + */ + public CompleteTask(Task task) { + this.task = task; + } + + /** + * Marks the duke.task.Task as done. + * @return The duke.Response. + */ + @Override + public Response execute() { + this.task.markDone(); + return this.respond(); + } + + /** + * Returns the duke.Response for marking the duke.task.Task as done. + * @return The duke.Response. + */ + private Response respond() { + return new Response(new String[]{ + "Nice! I've marked this task as done:", + String.format(" %s", this.task.toString()), + }); + } +} diff --git a/src/main/java/duke/action/DeleteTask.java b/src/main/java/duke/action/DeleteTask.java new file mode 100644 index 0000000000..05f05b6745 --- /dev/null +++ b/src/main/java/duke/action/DeleteTask.java @@ -0,0 +1,46 @@ +package duke.action; + +import duke.Response; +import duke.task.Task; +import duke.task.TaskCollection; + +/** + * duke.action.DeleteTask is an Action that deletes a duke.task.Task from a duke.task.TaskCollection. + */ +public class DeleteTask implements Action { + private final int taskId; + private final TaskCollection taskCollection; + + /** + * Creates an Action duke.action.DeleteTask that deletes a duke.task.Task from a duke.task.TaskCollection. + * @param taskId The identifier of the duke.task.Task to be deleted. + * @param taskCollection The duke.task.TaskCollection to delete the duke.task.Task from. + */ + public DeleteTask(int taskId, TaskCollection taskCollection) { + this.taskId = taskId; + this.taskCollection = taskCollection; + } + + /** + * Deletes the duke.task.Task from the duke.task.TaskCollection. + * @return The duke.Response. + */ + @Override + public Response execute() { + Task deletedTask = this.taskCollection.delete(this.taskId); + return this.respond(deletedTask); + } + + /** + * Returns the duke.Response for successfully adding the duke.task.Task to the duke.task.TaskCollection. + * @param deletedTask The duke.task.Task that was deleted. + * @return The duke.Response. + */ + private Response respond(Task deletedTask) { + return new Response(new String[]{ + "Noted. I've removed this task:", + String.format(" %s", deletedTask.toString()), + String.format("Now you have %d tasks in the list.", this.taskCollection.size()) + }); + } +} diff --git a/src/main/java/GoodbyeUser.java b/src/main/java/duke/action/GoodbyeUser.java similarity index 70% rename from src/main/java/GoodbyeUser.java rename to src/main/java/duke/action/GoodbyeUser.java index 99db719193..cdac98c1a3 100644 --- a/src/main/java/GoodbyeUser.java +++ b/src/main/java/duke/action/GoodbyeUser.java @@ -1,7 +1,12 @@ +package duke.action; + +import duke.Response; +import duke.action.Action; + public class GoodbyeUser implements Action { /** * Greets farewell to the user when the user requests to exit the application. - * @return The Response. + * @return The duke.Response. */ public Response execute() { return new Response(new String[]{ diff --git a/src/main/java/duke/action/ListTasks.java b/src/main/java/duke/action/ListTasks.java new file mode 100644 index 0000000000..9a1bcbb471 --- /dev/null +++ b/src/main/java/duke/action/ListTasks.java @@ -0,0 +1,40 @@ +package duke.action; + +import duke.Response; +import duke.action.Action; +import duke.task.TaskCollection; + +/** + * duke.action.ListTasks is an Action that lists the Tasks in a duke.task.TaskCollection. + */ +public class ListTasks implements Action { + private final TaskCollection taskCollection; + + /** + * Creates an Action duke.action.ListTasks that lists the Tasks in a duke.task.TaskCollection. + * @param taskCollection The duke.task.TaskCollection. + */ + public ListTasks(TaskCollection taskCollection) { + this.taskCollection = taskCollection; + } + + /** + * Lists all the Tasks in the duke.task.TaskCollection. + * @return The duke.Response. + */ + @Override + public Response execute() { + return this.respond(); + } + + /** + * Returns the duke.Response for listing all the Tasks in the duke.task.TaskCollection. + * @return The duke.Response. + */ + private Response respond() { + return new Response(new String[]{ + "Here are the tasks in your list:", + this.taskCollection.toString(), + }); + } +} diff --git a/src/main/java/WelcomeUser.java b/src/main/java/duke/action/WelcomeUser.java similarity index 60% rename from src/main/java/WelcomeUser.java rename to src/main/java/duke/action/WelcomeUser.java index e67d639f26..d1b9517ba3 100644 --- a/src/main/java/WelcomeUser.java +++ b/src/main/java/duke/action/WelcomeUser.java @@ -1,10 +1,15 @@ +package duke.action; + +import duke.Response; +import duke.action.Action; + /** - * WelcomeUser is an Action that greets the User. + * duke.action.WelcomeUser is an Action that greets the User. */ public class WelcomeUser implements Action { /** * Welcomes the user to the application. - * @return The Response. + * @return The duke.Response. */ public Response execute() { return new Response(new String[]{ diff --git a/src/main/java/duke/exception/UserException.java b/src/main/java/duke/exception/UserException.java new file mode 100644 index 0000000000..0361399020 --- /dev/null +++ b/src/main/java/duke/exception/UserException.java @@ -0,0 +1,27 @@ +package duke.exception; + +import duke.Response; + +import java.lang.Exception; + +/** + * A duke.exception.UserException represents an Exception thrown because of an invalid input by the User. + */ +public class UserException extends Exception { + private final String message; + + /** + * Create a duke.exception.UserException with the specified Message. + * @param message The message to be displayed in the duke.Response. + */ + public UserException(String message) { + this.message = message; + } + + /** + * Returns the duke.Response to be printed to the console of this duke.exception.UserException. + */ + public Response toResponse() { + return new Response(new String[]{ "☹ OOPS!!!", this.message }); + } +} diff --git a/src/main/java/duke/request/ByeRequest.java b/src/main/java/duke/request/ByeRequest.java new file mode 100644 index 0000000000..8701fcbb83 --- /dev/null +++ b/src/main/java/duke/request/ByeRequest.java @@ -0,0 +1,18 @@ +package duke.request; + +import duke.action.GoodbyeUser; +import duke.action.Action; + +/** + * duke.request.ByeRequest represents a request from the user to stop the application. + */ +public class ByeRequest extends Request { + /** + * Gets the Action the duke.request.ByeRequest requests to execute. + * @return The Action to be executed. + */ + @Override + public Action action() { + return new GoodbyeUser(); + } +} diff --git a/src/main/java/Command.java b/src/main/java/duke/request/Command.java similarity index 58% rename from src/main/java/Command.java rename to src/main/java/duke/request/Command.java index 5f86d430cc..ddde88d45b 100644 --- a/src/main/java/Command.java +++ b/src/main/java/duke/request/Command.java @@ -1,5 +1,9 @@ +package duke.request; + +import duke.exception.UserException; + /** - * A Command represents a string in a Request that instructs the application to perform an Action. + * A duke.request.Command represents a string in a duke.request.Request that instructs the application to perform an Action. */ public enum Command { BYE("bye"), @@ -11,22 +15,22 @@ public enum Command { TODO("todo"); /** - * The name of the Command. + * The name of the duke.request.Command. */ private final String name; /** - * Creates a Command with the specified name. - * @param name Name of the Command. + * Creates a duke.request.Command with the specified name. + * @param name Name of the duke.request.Command. */ Command(String name) { this.name = name; } /** - * Parses the input String to determine the related Command. + * Parses the input String to determine the related duke.request.Command. * @param commandString The input command String. - * @return The Command related to the command String. + * @return The duke.request.Command related to the command String. * @throws UserException If the command String is invalid. */ public static Command parseFrom(String commandString) throws UserException { diff --git a/src/main/java/DeadlineRequest.java b/src/main/java/duke/request/DeadlineRequest.java similarity index 67% rename from src/main/java/DeadlineRequest.java rename to src/main/java/duke/request/DeadlineRequest.java index 80624f5649..937a43c3b6 100644 --- a/src/main/java/DeadlineRequest.java +++ b/src/main/java/duke/request/DeadlineRequest.java @@ -1,5 +1,13 @@ +package duke.request; + +import duke.task.TaskCollection; +import duke.exception.UserException; +import duke.action.Action; +import duke.action.AddTask; +import duke.task.Deadline; + /** - * DeadlineRequest represents a request from the user to create a Deadline in the application. + * duke.request.DeadlineRequest represents a request from the user to create a duke.task.Deadline in the application. */ public class DeadlineRequest extends TaskCollectionRequest { private static final String BY_DELIMITER = " /by "; @@ -7,8 +15,8 @@ public class DeadlineRequest extends TaskCollectionRequest { private final Deadline deadline; /** - * Creates a DeadlineRequest. - * @param taskCollection The target TaskCollection. + * Creates a duke.request.DeadlineRequest. + * @param taskCollection The target duke.task.TaskCollection. * @param requestString The request String. * @throws UserException If the request String is invalid. */ @@ -18,7 +26,7 @@ protected DeadlineRequest(TaskCollection taskCollection, String requestString) t } /** - * Gets the Action the DeadlineRequest requests to execute. + * Gets the Action the duke.request.DeadlineRequest requests to execute. * @return The Action to be executed. */ @Override @@ -27,9 +35,9 @@ public Action action() { } /** - * Parses an input String to create a Deadline into a Deadline. + * Parses an input String to create a duke.task.Deadline into a duke.task.Deadline. * @param deadlineString The input String. - * @return The Deadline parsed from the input String. + * @return The duke.task.Deadline parsed from the input String. * @throws UserException If the deadlineString is invalid. */ private static Deadline parseDeadline(String deadlineString) throws UserException { diff --git a/src/main/java/DeleteRequest.java b/src/main/java/duke/request/DeleteRequest.java similarity index 62% rename from src/main/java/DeleteRequest.java rename to src/main/java/duke/request/DeleteRequest.java index 4f425d1b40..f9352894d3 100644 --- a/src/main/java/DeleteRequest.java +++ b/src/main/java/duke/request/DeleteRequest.java @@ -1,14 +1,21 @@ +package duke.request; + +import duke.action.DeleteTask; +import duke.task.TaskCollection; +import duke.exception.UserException; +import duke.action.Action; + import java.lang.NumberFormatException; /** - * DeleteRequest represents a request from the user to delete a Task from the TaskCollection. + * duke.request.DeleteRequest represents a request from the user to delete a duke.task.Task from the duke.task.TaskCollection. */ public class DeleteRequest extends TaskCollectionRequest { private final int taskId; /** - * Creates a DeleteRequest. - * @param taskCollection The target TaskCollection. + * Creates a duke.request.DeleteRequest. + * @param taskCollection The target duke.task.TaskCollection. * @param requestString The request String. * @throws UserException If the request String is invalid. */ @@ -22,7 +29,7 @@ protected DeleteRequest(TaskCollection taskCollection, String requestString) thr } /** - * Gets the Action the DeleteRequest requests to execute. + * Gets the Action the duke.request.DeleteRequest requests to execute. * @return The Action to be executed. */ @Override diff --git a/src/main/java/DoneRequest.java b/src/main/java/duke/request/DoneRequest.java similarity index 62% rename from src/main/java/DoneRequest.java rename to src/main/java/duke/request/DoneRequest.java index 2a9e44c815..dc621e0ff7 100644 --- a/src/main/java/DoneRequest.java +++ b/src/main/java/duke/request/DoneRequest.java @@ -1,14 +1,22 @@ +package duke.request; + +import duke.task.Task; +import duke.task.TaskCollection; +import duke.exception.UserException; +import duke.action.Action; +import duke.action.CompleteTask; + import java.lang.NumberFormatException; /** - * DoneRequest represents a request from the user to mark a Task as done in the application. + * duke.request.DoneRequest represents a request from the user to mark a duke.task.Task as done in the application. */ public class DoneRequest extends TaskCollectionRequest { private final int taskId; /** - * Creates a DoneRequest. - * @param taskCollection The target TaskCollection. + * Creates a duke.request.DoneRequest. + * @param taskCollection The target duke.task.TaskCollection. * @param requestString The request String. * @throws UserException If the request String is invalid. */ @@ -22,7 +30,7 @@ protected DoneRequest(TaskCollection taskCollection, String requestString) throw } /** - * Gets the Action the DoneRequest requests to execute. + * Gets the Action the duke.request.DoneRequest requests to execute. * @return The Action to be executed. */ @Override diff --git a/src/main/java/EventRequest.java b/src/main/java/duke/request/EventRequest.java similarity index 67% rename from src/main/java/EventRequest.java rename to src/main/java/duke/request/EventRequest.java index 8926f6feb4..2842f0f51d 100644 --- a/src/main/java/EventRequest.java +++ b/src/main/java/duke/request/EventRequest.java @@ -1,5 +1,13 @@ +package duke.request; + +import duke.action.Action; +import duke.action.AddTask; +import duke.exception.UserException; +import duke.task.Event; +import duke.task.TaskCollection; + /** - * EventRequest represents a request from the user to create an Event in the application. + * duke.request.EventRequest represents a request from the user to create an duke.task.Event in the application. */ public class EventRequest extends TaskCollectionRequest { private static final String AT_DELIMITER = " /at "; @@ -7,8 +15,8 @@ public class EventRequest extends TaskCollectionRequest { private final Event event; /** - * Creates a EventRequest. - * @param taskCollection The target TaskCollection. + * Creates a duke.request.EventRequest. + * @param taskCollection The target duke.task.TaskCollection. * @param requestString The request String. * @throws UserException If the request String is invalid. */ @@ -18,7 +26,7 @@ protected EventRequest(TaskCollection taskCollection, String requestString) thro } /** - * Gets the Action the EventRequest requests to execute. + * Gets the Action the duke.request.EventRequest requests to execute. * @return The Action to be executed. */ @Override @@ -27,9 +35,9 @@ public Action action() { } /** - * Parses an input String to create a Event into a Event. + * Parses an input String to create a duke.task.Event into a duke.task.Event. * @param eventString The input String. - * @return The Event parsed from the input String. + * @return The duke.task.Event parsed from the input String. * @throws UserException If the eventString is invalid. */ private static Event parseEvent(String eventString) throws UserException { diff --git a/src/main/java/duke/request/ListRequest.java b/src/main/java/duke/request/ListRequest.java new file mode 100644 index 0000000000..7dbc237743 --- /dev/null +++ b/src/main/java/duke/request/ListRequest.java @@ -0,0 +1,27 @@ +package duke.request; + +import duke.action.ListTasks; +import duke.action.Action; +import duke.task.TaskCollection; + +/** + * duke.request.ListRequest represents a request from the user to list all the Tasks in the application. + */ +public class ListRequest extends TaskCollectionRequest { + /** + * Creates a duke.request.ListRequest. + * @param taskCollection The target duke.task.TaskCollection. + */ + protected ListRequest(TaskCollection taskCollection) { + super(taskCollection); + } + + /** + * Gets the Action the duke.request.ListRequest requests to execute. + * @return The Action to be executed. + */ + @Override + public Action action() { + return new ListTasks(this.taskCollection); + } +} diff --git a/src/main/java/Request.java b/src/main/java/duke/request/Request.java similarity index 66% rename from src/main/java/Request.java rename to src/main/java/duke/request/Request.java index 7200a63e8d..4c6f951d6e 100644 --- a/src/main/java/Request.java +++ b/src/main/java/duke/request/Request.java @@ -1,20 +1,26 @@ +package duke.request; + +import duke.action.Action; +import duke.exception.UserException; +import duke.task.TaskCollection; + /** - * Request represents a request from the user to perform an action on a collection of tasks. + * duke.request.Request represents a request from the user to perform an action on a collection of tasks. */ public abstract class Request { private static final String COMMAND_DELIMITER = "\\s"; /** - * Gets the Action the Request requests to execute. + * Gets the Action the duke.request.Request requests to execute. * @return The Action to be executed. */ public abstract Action action(); /** - * Creates the Request related to the input requestString. - * @param taskCollection The TaskCollection to perform the Request on. + * Creates the duke.request.Request related to the input requestString. + * @param taskCollection The duke.task.TaskCollection to perform the duke.request.Request on. * @param requestString The request String. - * @return The Request related to the request String and TaskCollection. + * @return The duke.request.Request related to the request String and duke.task.TaskCollection. * @throws UserException If the request String is invalid. */ public static Request create(TaskCollection taskCollection, String requestString) throws UserException { @@ -43,7 +49,7 @@ public static Request create(TaskCollection taskCollection, String requestString } throw new RuntimeException(String.format( - "Command %s exists but is not mapped to a corresponding Request.", + "duke.request.Command %s exists but is not mapped to a corresponding duke.request.Request.", commandString )); } diff --git a/src/main/java/duke/request/TaskCollectionRequest.java b/src/main/java/duke/request/TaskCollectionRequest.java new file mode 100644 index 0000000000..b65a22702b --- /dev/null +++ b/src/main/java/duke/request/TaskCollectionRequest.java @@ -0,0 +1,18 @@ +package duke.request; + +import duke.task.TaskCollection; + +/** + * A duke.request.TaskCollectionRequest represents a duke.request.Request made to a duke.task.TaskCollection. + */ +public abstract class TaskCollectionRequest extends Request { + protected TaskCollection taskCollection; + + /** + * Creates a duke.request.TaskCollectionRequest to a specified Collection. + * @param taskCollection The Target duke.task.TaskCollection. + */ + protected TaskCollectionRequest(TaskCollection taskCollection) { + this.taskCollection = taskCollection; + } +} diff --git a/src/main/java/ToDoRequest.java b/src/main/java/duke/request/ToDoRequest.java similarity index 58% rename from src/main/java/ToDoRequest.java rename to src/main/java/duke/request/ToDoRequest.java index 3c055db8d3..9c599924a2 100644 --- a/src/main/java/ToDoRequest.java +++ b/src/main/java/duke/request/ToDoRequest.java @@ -1,12 +1,20 @@ +package duke.request; + +import duke.exception.UserException; +import duke.action.Action; +import duke.action.AddTask; +import duke.task.TaskCollection; +import duke.task.ToDo; + /** - * ToDoRequest represents a request from the user to create an ToDo in the application. + * duke.request.ToDoRequest represents a request from the user to create an duke.task.ToDo in the application. */ public class ToDoRequest extends TaskCollectionRequest { private final ToDo toDo; /** - * Creates a ToDoRequest. - * @param taskCollection The target TaskCollection. + * Creates a duke.request.ToDoRequest. + * @param taskCollection The target duke.task.TaskCollection. * @param requestString The request String. * @throws UserException If the request String is invalid. */ @@ -21,7 +29,7 @@ protected ToDoRequest(TaskCollection taskCollection, String requestString) throw } /** - * Gets the Action the ToDoRequest requests to execute. + * Gets the Action the duke.request.ToDoRequest requests to execute. * @return The Action to be executed. */ @Override diff --git a/src/main/java/Deadline.java b/src/main/java/duke/task/Deadline.java similarity index 60% rename from src/main/java/Deadline.java rename to src/main/java/duke/task/Deadline.java index 8dabc55888..be41438c62 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,42 +1,44 @@ -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; - -/** - * Deadline is a task that needs to be done before a specific date/time. - */ -public class Deadline extends Task { - protected LocalDate by; - - /** - * Creates a Deadline with the provided description and date/time. - * @param description The description of the Deadline task. - * @param by The date/time the Deadline needs to be done before. - */ - public Deadline(String description, String by) { - super(description); - this.by = LocalDate.parse(by); - } - - /** - * Converts the Deadline into a String that represents the Deadline. - * @return The String representation of a Deadline. - */ - @Override - public String toString() { - return String.format("[%s]%s (by: %s)", TaskType.DEADLINE.toString(), super.toString(), this.by.format(DateTimeFormatter.ofPattern("dd MMM yyyy"))); - } - - /** - * Converts the Deadline into a String to be stored in Storage. - * @return String to be stored - */ - @Override - public String toStorageString() { - String taskString = super.toStorageString(); - return TaskType.DEADLINE.toString() - + Task.STORAGE_STRING_DELIMITER - + taskString - + Task.STORAGE_STRING_DELIMITER - + this.by; - } -} +package duke.task; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * duke.task.Deadline is a task that needs to be done before a specific date/time. + */ +public class Deadline extends Task { + protected LocalDate by; + + /** + * Creates a duke.task.Deadline with the provided description and date/time. + * @param description The description of the duke.task.Deadline task. + * @param by The date/time the duke.task.Deadline needs to be done before. + */ + public Deadline(String description, String by) { + super(description); + this.by = LocalDate.parse(by); + } + + /** + * Converts the duke.task.Deadline into a String that represents the duke.task.Deadline. + * @return The String representation of a duke.task.Deadline. + */ + @Override + public String toString() { + return String.format("[%s]%s (by: %s)", TaskType.DEADLINE.toString(), super.toString(), this.by.format(DateTimeFormatter.ofPattern("dd MMM yyyy"))); + } + + /** + * Converts the duke.task.Deadline into a String to be stored in duke.Storage. + * @return String to be stored + */ + @Override + public String toStorageString() { + String taskString = super.toStorageString(); + return TaskType.DEADLINE.toString() + + Task.STORAGE_STRING_DELIMITER + + taskString + + Task.STORAGE_STRING_DELIMITER + + this.by; + } +} diff --git a/src/main/java/Event.java b/src/main/java/duke/task/Event.java similarity index 60% rename from src/main/java/Event.java rename to src/main/java/duke/task/Event.java index 9388c61cd4..afe270efef 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,42 +1,44 @@ -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; - -/** - * An Event is a task that start at a specific time and ends at a specific time. - */ -public class Event extends Task { - protected LocalDate at; - - /** - * Creates an Event with the provided description and start and end date/time. - * @param description The description of the Event task. - * @param at The date/time of the Event. - */ - public Event(String description, String at) { - super(description); - this.at = LocalDate.parse(at); - } - - /** - * Converts the Event into a String that represents the Event. - * @return The String representation of a Event. - */ - @Override - public String toString() { - return String.format("[%s]%s (at: %s)", TaskType.EVENT.toString(), super.toString(), this.at.format(DateTimeFormatter.ofPattern("dd MMM yyyy"))); - } - - /** - * Converts the Event into a String to be stored in Storage. - * @return String to be stored - */ - @Override - public String toStorageString() { - String taskString = super.toStorageString(); - return TaskType.EVENT.toString() - + Task.STORAGE_STRING_DELIMITER - + taskString - + Task.STORAGE_STRING_DELIMITER - + this.at; - } -} +package duke.task; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * An duke.task.Event is a task that start at a specific time and ends at a specific time. + */ +public class Event extends Task { + protected LocalDate at; + + /** + * Creates an duke.task.Event with the provided description and start and end date/time. + * @param description The description of the duke.task.Event task. + * @param at The date/time of the duke.task.Event. + */ + public Event(String description, String at) { + super(description); + this.at = LocalDate.parse(at); + } + + /** + * Converts the duke.task.Event into a String that represents the duke.task.Event. + * @return The String representation of a duke.task.Event. + */ + @Override + public String toString() { + return String.format("[%s]%s (at: %s)", TaskType.EVENT.toString(), super.toString(), this.at.format(DateTimeFormatter.ofPattern("dd MMM yyyy"))); + } + + /** + * Converts the duke.task.Event into a String to be stored in duke.Storage. + * @return String to be stored + */ + @Override + public String toStorageString() { + String taskString = super.toStorageString(); + return TaskType.EVENT.toString() + + Task.STORAGE_STRING_DELIMITER + + taskString + + Task.STORAGE_STRING_DELIMITER + + this.at; + } +} diff --git a/src/main/java/Task.java b/src/main/java/duke/task/Task.java similarity index 71% rename from src/main/java/Task.java rename to src/main/java/duke/task/Task.java index 50cc6127bb..df14d35c62 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,5 +1,7 @@ +package duke.task; + /** - * Task is the base class for all tasks stored in the Duke application. + * duke.task.Task is the base class for all tasks stored in the Duke application. */ public class Task { private static final String NOT_DONE_STATUS_ICON = " "; @@ -22,6 +24,13 @@ public Task(String description) { this.isDone = false; } + /** + * Marks a task as done. + */ + public void markDone() { + this.isDone = true; + } + /** * Gets the String icon that represents the status of the task. * @return The String icon. @@ -31,8 +40,8 @@ public String getStatusIcon() { } /** - * Converts the Task into a String that represents the Task. - * @return The String representation of a Task. + * Converts the duke.task.Task into a String that represents the duke.task.Task. + * @return The String representation of a duke.task.Task. */ @Override public String toString() { @@ -40,7 +49,7 @@ public String toString() { } /** - * Converts the Task into a String to be stored in Storage. + * Converts the duke.task.Task into a String to be stored in duke.Storage. * @return String to be stored */ public String toStorageString() { @@ -49,9 +58,9 @@ public String toStorageString() { } /** - * Parses a storage String into a Task object. - * @param string The String used to represent the Task in the Storage. - * @return The Task represented by the Storage String. + * Parses a storage String into a duke.task.Task object. + * @param string The String used to represent the duke.task.Task in the duke.Storage. + * @return The duke.task.Task represented by the duke.Storage String. */ public static Task fromStorageString(String string) { String[] taskSubstrings = string.split(Task.STORAGE_STRING_PARSING_DELIMITER); @@ -70,7 +79,7 @@ public static Task fromStorageString(String string) { break; default: throw new RuntimeException( - String.format("TaskType %s is not accounted for in switch statement.", taskType.toString()) + String.format("duke.task.TaskType %s is not accounted for in switch statement.", taskType.toString()) ); } diff --git a/src/main/java/TaskCollection.java b/src/main/java/duke/task/TaskCollection.java similarity index 69% rename from src/main/java/TaskCollection.java rename to src/main/java/duke/task/TaskCollection.java index 61792efc7e..c1c952d5c1 100644 --- a/src/main/java/TaskCollection.java +++ b/src/main/java/duke/task/TaskCollection.java @@ -1,17 +1,20 @@ -import java.lang.reflect.Array; +package duke.task; + +import duke.Storage; + import java.util.ArrayList; import java.util.List; /** - * TaskCollection represents the collection of tasks stored in the Duke application. + * duke.task.TaskCollection represents the collection of tasks stored in the Duke application. */ public class TaskCollection { private List tasks = new ArrayList<>(); private final Storage storage; /** - * Creates a TaskCollection that consists of a Storage file at the specified pathname. - * @param pathname Pathname of the Storage file + * Creates a duke.task.TaskCollection that consists of a duke.Storage file at the specified pathname. + * @param pathname Pathname of the duke.Storage file */ public TaskCollection(String pathname) { this.storage = new Storage(pathname); @@ -19,7 +22,7 @@ public TaskCollection(String pathname) { } /** - * Saves the List of Tasks into the TaskCollection's Storage file. + * Saves the List of Tasks into the duke.task.TaskCollection's duke.Storage file. */ public void saveTasks() { StringBuilder taskCollectionString = new StringBuilder(); @@ -65,7 +68,7 @@ private List parse(String string) { } /** - * Adds a task to the TaskCollection. + * Adds a task to the duke.task.TaskCollection. * @param task The task to be added. */ public void add(Task task) { @@ -73,16 +76,16 @@ public void add(Task task) { } /** - * Gets a task from the TaskCollection. - * @param identifier The Task's identifier. + * Gets a task from the duke.task.TaskCollection. + * @param identifier The duke.task.Task's identifier. */ public Task get(int identifier) { return this.tasks.get(identifier - 1); } /** - * Get the number of Tasks in the TaskCollection. - * @return The size of the TaskCollection. + * Get the number of Tasks in the duke.task.TaskCollection. + * @return The size of the duke.task.TaskCollection. */ public Task delete(int identifier) { Task deletedTask = this.tasks.remove(identifier - 1); @@ -90,16 +93,16 @@ public Task delete(int identifier) { } /** - * Get the number of Tasks in the TaskCollection. - * @return The size of the TaskCollection. + * Get the number of Tasks in the duke.task.TaskCollection. + * @return The size of the duke.task.TaskCollection. */ public int size() { return this.tasks.size(); } /** - * Converts the TaskCollection to its String representation. - * @return The String representation of the TaskCollection. + * Converts the duke.task.TaskCollection to its String representation. + * @return The String representation of the duke.task.TaskCollection. */ @Override public String toString() { diff --git a/src/main/java/duke/task/TaskType.java b/src/main/java/duke/task/TaskType.java new file mode 100644 index 0000000000..8e49fbd689 --- /dev/null +++ b/src/main/java/duke/task/TaskType.java @@ -0,0 +1,46 @@ +package duke.task; + +/** + * A duke.task.TaskType represents a type of duke.task.Task in the application. + */ +public enum TaskType { + DEADLINE("D"), + EVENT("E"), + TODO("T"); + + /** + * The name of the duke.task.Task. + */ + private final String name; + + /** + * Creates a duke.task.TaskType with the specified name. + * @param name Name of the duke.task.TaskType. + */ + TaskType(String name) { + this.name = name; + } + + /** + * Gets the String representation of the duke.task.TaskType. + * @return The String representation of the duke.task.TaskType + */ + @Override + public String toString() { + return this.name; + } + + /** + * Parse the input String into an equivalent duke.task.TaskType. + * @return The equivalent duke.task.TaskType. + */ + public static TaskType parse(String string) { + for (TaskType taskType : TaskType.values()) { + if (taskType.name.equals(string)) { + return taskType; + } + } + + throw new RuntimeException(String.format("Invalid duke.task.TaskType string %s.", string)); + } +} diff --git a/src/main/java/ToDo.java b/src/main/java/duke/task/ToDo.java similarity index 57% rename from src/main/java/ToDo.java rename to src/main/java/duke/task/ToDo.java index 0b85530c04..e669b806e3 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/duke/task/ToDo.java @@ -1,18 +1,23 @@ +package duke.task; + +import duke.task.Task; +import duke.task.TaskType; + /** * Todo is a task without any date/time attached to it. */ public class ToDo extends Task { /** - * Creates a ToDo with the provided description. - * @param description The description of the ToDo. + * Creates a duke.task.ToDo with the provided description. + * @param description The description of the duke.task.ToDo. */ public ToDo(String description) { super(description); } /** - * Converts the ToDo into a String that represents the ToDo. - * @return The String representation of a ToDo. + * Converts the duke.task.ToDo into a String that represents the duke.task.ToDo. + * @return The String representation of a duke.task.ToDo. */ @Override public String toString() { @@ -20,7 +25,7 @@ public String toString() { } /** - * Converts the Event into a String to be stored in Storage. + * Converts the duke.task.Event into a String to be stored in duke.Storage. * @return String to be stored */ @Override