diff --git a/data/duke.txt b/data/duke.txt index 89eb36c3e..e69de29bb 100644 --- a/data/duke.txt +++ b/data/duke.txt @@ -1,4 +0,0 @@ -T|X|coffee -T| |coffee 2 -D| |coffee /by: 2pm -E| |coffee again /from: 1pm /by: 2pm diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 91ad8b295..627acc6c0 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,23 +1,24 @@ public class Deadline extends Todo { protected String by; + + /** Creates a deadline-type task, which contains a description and completion timing */ public Deadline(String description, String by) { super(description); setBy(by); } + /** Sets the completion timing of the task */ public void setBy(String by) { this.by = by; } - public String getBy() { - return this.by; - } - + /** Returns type of task (deadline) */ @Override public String getType() { return "deadline"; } + /** Returns completion timing of task */ @Override public String getTimings() { return this.by; diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 14e565001..b87bac80b 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,21 +1,26 @@ public class Event extends Task{ protected String start; protected String end; + + /** Creates an event-type task, which contains a description and start and end timing */ public Event(String description, String start, String end) { super(description); setStartEnd(start, end); } + /** Sets the start and end timing of the task */ public void setStartEnd (String start, String end) { this.start = start; this.end = end; } + /** Returns type of task (event) */ @Override public String getType() { return "event"; } + /** Returns start and end timing as a single string, separated by a slash */ @Override public String getTimings() { return this.start + "/" + this.end; diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index c8f4658a7..6656494d6 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -2,6 +2,7 @@ public class Parser { + /** Parses user command and calls relevant functions */ public static void parseCommand(String taskInfo, ArrayList tasks) { if (taskInfo.equals("list")) { getList(tasks); @@ -53,12 +54,14 @@ public static void parseCommand(String taskInfo, ArrayList tasks) { } } + /** Prints list of all tasks */ public static void getList(ArrayList tasks) { for (int i = 0; i < tasks.size(); i++) { System.out.println((i + 1) + "." + Ui.printTask(tasks.get(i))); } } + /** Finds tasks based on a specific keyword */ public static void findTask(ArrayList tasks, String taskDescription) { int taskNo = 0; for (Task task: tasks) { diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 7a87f3c29..4a805cdbb 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -10,6 +10,7 @@ public class Storage { private static final String FILEPATH = "data/duke.txt"; + /** Writes tasks to file after user exits */ static void writeToFile(ArrayList tasks) throws IOException { Files.createDirectories(Paths.get("./data")); try { @@ -48,6 +49,7 @@ static void writeToFile(ArrayList tasks) throws IOException { } + /** Loads tasks from previous save files when starting Duke */ static ArrayList loadFromFile() { ArrayList tasks = new ArrayList(); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 9cb71c904..b03e6af1e 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -3,28 +3,34 @@ public abstract class Task { protected boolean isDone; protected String type; + /** Creates a task, which must contain a description */ public Task(String description) { this.description = description; this.isDone = false; } + /** Returns whether a task is complete or incomplete */ public String getStatusIcon() { // mark done task with X return (isDone ? "X" : " "); } + /** Marks a task as done */ public void markAsDone(){ isDone = true; } + /** Marks a task as not done */ public void unmarkAsDone(){ isDone = false; } + /** Returns type of task */ public String getType() { return null; } + /** Returns relevant timings of task, if any */ public String getTimings() { return null; } diff --git a/src/main/java/Tasklist.java b/src/main/java/Tasklist.java index 306d63c70..d115288c5 100644 --- a/src/main/java/Tasklist.java +++ b/src/main/java/Tasklist.java @@ -5,12 +5,14 @@ public class Tasklist { private static final int FROM_LEN = 6; private static final int BY_LEN = 4; + /** Adds a todo-type task */ static void addTodo(ArrayList tasks, String taskDescription) { Task newTodo = new Todo(taskDescription); tasks.add(newTodo); System.out.println("Created todo: " + Ui.printTask(newTodo)); } + /** Adds a deadline-type task */ static void addDeadline(ArrayList tasks, String taskDescription) { int deadlineByIndex = taskDescription.indexOf("/"); @@ -22,6 +24,7 @@ static void addDeadline(ArrayList tasks, String taskDescription) { System.out.println("Created deadline: " + Ui.printTask(newDeadline)); } + /** Adds an event-type task */ static void addEvent(ArrayList tasks, String taskDescription) { int eventStartIndex = taskDescription.indexOf("/"); int eventEndIndex = taskDescription.lastIndexOf("/"); @@ -36,14 +39,17 @@ static void addEvent(ArrayList tasks, String taskDescription) { } + /** Mark a task as complete */ static void markTask(ArrayList tasks, int taskNo) { tasks.get(taskNo).markAsDone(); } + /** Mark a task as incomplete */ static void unmarkTask(ArrayList tasks, int taskNo) { tasks.get(taskNo).unmarkAsDone(); } + /** Delete a task by task number */ static void deleteTask(ArrayList tasks, int taskNo) { if (tasks.size() > 0) { System.out.println("Got it! This task will be removed:"); diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 19c2d24bb..5b48ea5f9 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,10 +1,13 @@ public class Todo extends Task { protected boolean isDone; + + /** Creates a todo-type task, which contains a description */ public Todo(String description) { super(description); isDone = false; } + /** Returns type of task (todo) */ @Override public String getType() { return "todo"; diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index fa6cc83c4..2924c1b63 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -2,6 +2,7 @@ public class Ui { + /** Display message when loading previously saved tasks */ static void loadDataMessage() { System.out.println(("Loading previous save data...")); } @@ -15,11 +16,13 @@ static void goodbyeMessage() { System.out.println("Bye! :D"); } + /** Reads the next user command */ static String readCommand() { Scanner reader = new Scanner(System.in); return reader.nextLine(); } + /** Format printing of task by task type */ static String printTask(Task task) { String taskType = task.getType(); String formattedTask;