From 6118ea3bf12ac1af4222fd9d07dfbfad0a760ec4 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Thu, 26 Jan 2023 02:34:49 +0800 Subject: [PATCH 01/22] Level-0 --- .gitignore | 1 + src/main/java/Duke.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 2873e189e..b4f8d00ac 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT +src/main/java/Duke.class diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..b8b566509 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,5 +6,8 @@ public static void main(String[] args) { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you ?"); + System.out.println("Bye. Hope to see you again soon !"); } } From 9877b901dc55b31b0c85f3b360fde92591e77155 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Thu, 26 Jan 2023 02:48:24 +0800 Subject: [PATCH 02/22] Add ability to echo input --- src/main/java/Duke.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index b8b566509..abd7dc1a9 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class Duke { public static void main(String[] args) { String logo = " ____ _ \n" @@ -8,6 +10,12 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you ?"); + Scanner ScanObj = new Scanner(System.in); + String UserCmd = "no"; + while (!UserCmd.equals("bye")) { + UserCmd = ScanObj.nextLine(); + System.out.println(UserCmd); + } System.out.println("Bye. Hope to see you again soon !"); } } From bc1e77d35764b8254fceab6a2ac7479fa868b39f Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Thu, 26 Jan 2023 14:08:22 +0800 Subject: [PATCH 03/22] Add the ability to read and store user commands --- src/main/java/Duke.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index abd7dc1a9..3ab6b09f7 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -11,10 +11,28 @@ public static void main(String[] args) { System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you ?"); Scanner ScanObj = new Scanner(System.in); - String UserCmd = "no"; + String[] listofItems = new String[100]; + String UserCmd = ScanObj.nextLine(); + int counter = 0; while (!UserCmd.equals("bye")) { + if (UserCmd.equals("list")) { + int j = 1; + for (String i : listofItems) { + System.out.print(j); + System.out.print(". "); + System.out.println(i); + j++; + if (j > counter) { + break; + } + } + } else { + System.out.print("added: "); + System.out.println(UserCmd); + listofItems[counter] = UserCmd; + counter++; + } UserCmd = ScanObj.nextLine(); - System.out.println(UserCmd); } System.out.println("Bye. Hope to see you again soon !"); } From 012958edaf56d70993f4c9f5558999a6b9a7e88e Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Fri, 27 Jan 2023 11:17:05 +0800 Subject: [PATCH 04/22] Added Task and TaskManager as the class, add Duke's abiity to record, mark and unmark task --- .gitignore | 2 ++ src/main/java/Duke.java | 28 ++++++++++++------------ src/main/java/Task.java | 40 ++++++++++++++++++++++++++++++++++ src/main/java/TaskManager.java | 40 ++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 src/main/java/Task.java create mode 100644 src/main/java/TaskManager.java diff --git a/.gitignore b/.gitignore index b4f8d00ac..6607a2f28 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT src/main/java/Duke.class +src/main/java/Task.class +src/main/java/TaskManager.class diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 3ab6b09f7..ad4aba7e2 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -11,26 +11,26 @@ public static void main(String[] args) { System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you ?"); Scanner ScanObj = new Scanner(System.in); - String[] listofItems = new String[100]; + + TaskManager listofItems = new TaskManager(); String UserCmd = ScanObj.nextLine(); - int counter = 0; + int taskId = 0; while (!UserCmd.equals("bye")) { + String[] WordsinUserCmd = UserCmd.split(" "); + System.out.println(WordsinUserCmd[0]); if (UserCmd.equals("list")) { - int j = 1; - for (String i : listofItems) { - System.out.print(j); - System.out.print(". "); - System.out.println(i); - j++; - if (j > counter) { - break; - } - } + listofItems.listTask(); + } else if (WordsinUserCmd[0].equals("mark")) { + System.out.println("this is a mark command"); + listofItems.markTask(Integer.parseInt(WordsinUserCmd[1]) - 1); + } else if (WordsinUserCmd[0].equals("unmark")) { + System.out.println("this is a unmark command"); + listofItems.unmarkTask(Integer.parseInt(WordsinUserCmd[1]) - 1); } else { System.out.print("added: "); System.out.println(UserCmd); - listofItems[counter] = UserCmd; - counter++; + listofItems.addTask(UserCmd, taskId); + taskId++; } UserCmd = ScanObj.nextLine(); } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..6d168fbe8 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,40 @@ +public class Task { + private String name; + private boolean isDone; + private int taskId; + + public Task(String name, boolean isDone, int taskId) { + this.name = name; + this.isDone = isDone; + this.taskId = taskId; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean IsDone() { + return this.isDone; + } + + public boolean getIsDone() { + return this.isDone; + } + + public void setIsDone(boolean isDone) { + this.isDone = isDone; + } + + public int getTaskId() { + return this.taskId; + } + + public void setTaskId(int taskId) { + this.taskId = taskId; + } + +} diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java new file mode 100644 index 000000000..b960f7fe2 --- /dev/null +++ b/src/main/java/TaskManager.java @@ -0,0 +1,40 @@ +public class TaskManager { + private Task[] Tasks = new Task[100]; + private int TasksCount = 0; + + public void addTask(String name, int id) { + Tasks[TasksCount] = new Task(name, false, id); + TasksCount++; + } + + public void markTask(int id) { + Tasks[id].setIsDone(true); + System.out.println("The task has been marked as done!"); + System.out.println("[X] " + Tasks[id].getName()); + } + + public void unmarkTask(int id) { + Tasks[id].setIsDone(false); + System.out.println("The task has been marked as NOT done!"); + System.out.println("[ ] " + Tasks[id].getName()); + } + + public void listTask() { + int j = 1; + for (Task i : Tasks) { + if (i.getIsDone() == true) { + System.out.print(j); + System.out.print(" [X] "); + System.out.println(i.getName()); + } else { + System.out.print(j); + System.out.print(" [ ] "); + System.out.println(i.getName()); + } + j++; + if (j > TasksCount) { + break; + } + } + } +} From ba5a640162ca9474e1fee19567f7ba9275698c26 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Mon, 30 Jan 2023 14:44:35 +0800 Subject: [PATCH 05/22] fix some variable-naming issues and fix further formatting issues in compliance with coding standard --- src/main/java/Duke.java | 30 ++++++++++++++++-------------- src/main/java/TaskManager.java | 20 ++++++++++---------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index ad4aba7e2..784f38665 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -10,30 +10,32 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you ?"); - Scanner ScanObj = new Scanner(System.in); - + Scanner scanObj = new Scanner(System.in); TaskManager listofItems = new TaskManager(); - String UserCmd = ScanObj.nextLine(); + String userCmd = scanObj.nextLine(); int taskId = 0; - while (!UserCmd.equals("bye")) { - String[] WordsinUserCmd = UserCmd.split(" "); - System.out.println(WordsinUserCmd[0]); - if (UserCmd.equals("list")) { + + while (!userCmd.equals("bye")) { + String[] userCmdasWords = userCmd.split(" "); + System.out.println(userCmdasWords[0]); + if (userCmd.equals("list")) { listofItems.listTask(); - } else if (WordsinUserCmd[0].equals("mark")) { + } else if (userCmdasWords[0].equals("mark")) { System.out.println("this is a mark command"); - listofItems.markTask(Integer.parseInt(WordsinUserCmd[1]) - 1); - } else if (WordsinUserCmd[0].equals("unmark")) { + listofItems.markTask(Integer.parseInt(userCmdasWords[1]) - 1); + } else if (userCmdasWords[0].equals("unmark")) { System.out.println("this is a unmark command"); - listofItems.unmarkTask(Integer.parseInt(WordsinUserCmd[1]) - 1); + listofItems.unmarkTask(Integer.parseInt(userCmdasWords[1]) - 1); } else { System.out.print("added: "); - System.out.println(UserCmd); - listofItems.addTask(UserCmd, taskId); + System.out.println(userCmd); + listofItems.addTask(userCmd, taskId); taskId++; } - UserCmd = ScanObj.nextLine(); + userCmd = scanObj.nextLine(); } + + scanObj.close(); System.out.println("Bye. Hope to see you again soon !"); } } diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index b960f7fe2..e29f46451 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,27 +1,27 @@ public class TaskManager { - private Task[] Tasks = new Task[100]; - private int TasksCount = 0; + private Task[] tasks = new Task[100]; + private int tasksCount = 0; public void addTask(String name, int id) { - Tasks[TasksCount] = new Task(name, false, id); - TasksCount++; + tasks[tasksCount] = new Task(name, false, id); + tasksCount++; } public void markTask(int id) { - Tasks[id].setIsDone(true); + tasks[id].setIsDone(true); System.out.println("The task has been marked as done!"); - System.out.println("[X] " + Tasks[id].getName()); + System.out.println("[X] " + tasks[id].getName()); } public void unmarkTask(int id) { - Tasks[id].setIsDone(false); + tasks[id].setIsDone(false); System.out.println("The task has been marked as NOT done!"); - System.out.println("[ ] " + Tasks[id].getName()); + System.out.println("[ ] " + tasks[id].getName()); } public void listTask() { int j = 1; - for (Task i : Tasks) { + for (Task i : tasks) { if (i.getIsDone() == true) { System.out.print(j); System.out.print(" [X] "); @@ -32,7 +32,7 @@ public void listTask() { System.out.println(i.getName()); } j++; - if (j > TasksCount) { + if (j > tasksCount) { break; } } From 09c76af478545c57d6451ef7267c5ee157177b34 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Sun, 5 Feb 2023 03:30:12 +0800 Subject: [PATCH 06/22] Add Deadline and Event as subclasses --- src/main/java/Duke.java | 124 ++++++++++++++++++++++++++++----- src/main/java/Task.java | 22 +++++- src/main/java/TaskManager.java | 33 ++++----- 3 files changed, 142 insertions(+), 37 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 784f38665..b125222a5 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,6 +1,75 @@ import java.util.Scanner; public class Duke { + + public static void printInstructions() { + System.out.println("LIST OF ALL COMMANDS:"); + System.out.println("todo + \"task name\" to add a task"); + System.out.println("deadline + \"task name\" + /by \"task deadline\" to add a task with a deadline"); + System.out.println( + "event + \"event name\" + /from \"event start time\" + /to \"event finish time\" to add an event with a stant and finish time"); + System.out.println("list to list all events and tasks available"); + } + + public static void printHorizontalLine() { + for (int i = 0; i <= 30; i++) { + System.out.print("_"); + } + System.out.println(); + } + + public static void falseInput() { + System.out.println("Sorry Duke could not understand your input :> please follow the instructions"); + printInstructions(); + } + + public static String firstWord(String s) { + String a[] = s.split(" "); + return a[0]; + } + + public static void executeAddTodo(String s, int taskId, TaskManager listofItems) { + s = s.substring("todo ".length(), s.length()); + listofItems.addTask(s, taskId); + System.out.println("Roger. The following todo has been added:"); + System.out.println("[T][ ] " + s); + System.out.println("You now have " + (taskId + 1) + " item in the list"); + } + + public static void executeAddDeadline(String s, int taskId, TaskManager listofItems) { + s = s.substring("deadline ".length(), s.length()); + String[] cmd = s.split(" /by "); + if (cmd.length == 1) { + System.out.println("Sorry, it seems like you forgot to input the deadline. Please read instructions again"); + printInstructions(); + } else if (cmd.length > 2) { + System.out.println("Sorry, it seems like you input more than one deadline. Please read instructions again"); + printInstructions(); + } else { + listofItems.addDeadline(cmd[0], cmd[1], taskId); + System.out.println("Roger. The following deadline has been added:"); + System.out.println("[D][ ] " + cmd[0] + " (by: " + cmd[1] + ")"); + System.out.println("You now have " + (taskId + 1) + " item in the list"); + } + } + + public static void executeAddEvent(String s, int taskId, TaskManager listofItems) { + s = s.substring("event ".length(), s.length()); + String[] cmd = s.split(" /from "); + if (cmd.length == 1) { + System.out + .println("Sorry, it seems like you forgot to input the start time. Please read instructions again"); + printInstructions(); + } else { + String startTime = cmd[1].split(" /to ")[0]; + String endTime = cmd[1].split(" /to ")[1]; + listofItems.addEvent(cmd[0], startTime, endTime, taskId); + System.out.println("Roger. The following event has been added:"); + System.out.println("[E][ ] " + cmd[0] + " (from: " + startTime + " to: " + endTime + ")"); + System.out.println("You now have " + (taskId + 1) + " item in the list"); + } + } + public static void main(String[] args) { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -10,32 +79,51 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("Hello! I'm Duke"); System.out.println("What can I do for you ?"); + printHorizontalLine(); + printInstructions(); + printHorizontalLine(); Scanner scanObj = new Scanner(System.in); TaskManager listofItems = new TaskManager(); String userCmd = scanObj.nextLine(); int taskId = 0; - while (!userCmd.equals("bye")) { - String[] userCmdasWords = userCmd.split(" "); - System.out.println(userCmdasWords[0]); - if (userCmd.equals("list")) { - listofItems.listTask(); - } else if (userCmdasWords[0].equals("mark")) { - System.out.println("this is a mark command"); - listofItems.markTask(Integer.parseInt(userCmdasWords[1]) - 1); - } else if (userCmdasWords[0].equals("unmark")) { - System.out.println("this is a unmark command"); - listofItems.unmarkTask(Integer.parseInt(userCmdasWords[1]) - 1); - } else { - System.out.print("added: "); - System.out.println(userCmd); - listofItems.addTask(userCmd, taskId); - taskId++; + switch (firstWord(userCmd)) { + case "todo": + executeAddTodo(userCmd, taskId, listofItems); + printHorizontalLine(); + taskId++; + break; + case "deadline": + executeAddDeadline(userCmd, taskId, listofItems); + printHorizontalLine(); + taskId++; + break; + case "event": + executeAddEvent(userCmd, taskId, listofItems); + printHorizontalLine(); + taskId++; + break; + case "list": + listofItems.listTask(); + printHorizontalLine(); + break; + case "mark": + String markId[] = userCmd.split(" "); + listofItems.markTask(Integer.parseInt(markId[1]) - 1); + printHorizontalLine(); + break; + case "unmark": + String unmarkId[] = userCmd.split(" "); + listofItems.unmarkTask(Integer.parseInt(unmarkId[1]) - 1); + printHorizontalLine(); + break; + default: + falseInput(); + printHorizontalLine(); } userCmd = scanObj.nextLine(); } - scanObj.close(); - System.out.println("Bye. Hope to see you again soon !"); + System.out.println("Bye. Duke hopes to see you again soon !"); } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 6d168fbe8..c6c12f293 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -2,6 +2,19 @@ public class Task { private String name; private boolean isDone; private int taskId; + private char taskType; + + public boolean isIsDone() { + return this.isDone; + } + + public char getTaskType() { + return this.taskType; + } + + public void setTaskType(char taskType) { + this.taskType = taskType; + } public Task(String name, boolean isDone, int taskId) { this.name = name; @@ -17,7 +30,7 @@ public void setName(String name) { this.name = name; } - public boolean IsDone() { + public boolean isDone() { return this.isDone; } @@ -37,4 +50,11 @@ public void setTaskId(int taskId) { this.taskId = taskId; } + public void print() { + if (this.isDone == false) { + System.out.println((this.taskId + 1) + ".[T][ ] " + this.name); + } else { + System.out.println((this.taskId + 1) + ".[T][X] " + this.name); + } + } } diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index e29f46451..adb23ff89 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,10 +1,20 @@ public class TaskManager { private Task[] tasks = new Task[100]; - private int tasksCount = 0; + private int taskCount = 0; public void addTask(String name, int id) { - tasks[tasksCount] = new Task(name, false, id); - tasksCount++; + tasks[taskCount] = new Task(name, false, id); + taskCount++; + } + + public void addDeadline(String name, String deadline, int id) { + tasks[taskCount] = new Deadline(name, false, id, deadline); + taskCount++; + } + + public void addEvent(String eventName, String startTime, String finishTime, int id) { + tasks[taskCount] = new Event(eventName, false, id, startTime, finishTime); + taskCount++; } public void markTask(int id) { @@ -20,21 +30,8 @@ public void unmarkTask(int id) { } public void listTask() { - int j = 1; - for (Task i : tasks) { - if (i.getIsDone() == true) { - System.out.print(j); - System.out.print(" [X] "); - System.out.println(i.getName()); - } else { - System.out.print(j); - System.out.print(" [ ] "); - System.out.println(i.getName()); - } - j++; - if (j > tasksCount) { - break; - } + for (int i = 0; i < taskCount; i++) { + tasks[i].print(); } } } From dc4925f5e53deeb2a9ae6828bb792a77a08b2230 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Sun, 5 Feb 2023 03:31:08 +0800 Subject: [PATCH 07/22] fix commit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6607a2f28..0c9fc9f2b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ text-ui-test/EXPECTED-UNIX.TXT src/main/java/Duke.class src/main/java/Task.class src/main/java/TaskManager.class +*.class +*.java From 97f41d123e7f8cdc758e347da4f05d038a1a3244 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Sun, 5 Feb 2023 03:40:51 +0800 Subject: [PATCH 08/22] Tidy up the Duke class a little bit by refactoring and shorter print lines --- src/main/java/Duke.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index b125222a5..24bc0b14d 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -40,10 +40,10 @@ public static void executeAddDeadline(String s, int taskId, TaskManager listofIt s = s.substring("deadline ".length(), s.length()); String[] cmd = s.split(" /by "); if (cmd.length == 1) { - System.out.println("Sorry, it seems like you forgot to input the deadline. Please read instructions again"); + System.out.println("Missing deadline. Please read instructions again"); printInstructions(); } else if (cmd.length > 2) { - System.out.println("Sorry, it seems like you input more than one deadline. Please read instructions again"); + System.out.println("Too many deadlines. Please read instructions again"); printInstructions(); } else { listofItems.addDeadline(cmd[0], cmd[1], taskId); @@ -57,8 +57,7 @@ public static void executeAddEvent(String s, int taskId, TaskManager listofItems s = s.substring("event ".length(), s.length()); String[] cmd = s.split(" /from "); if (cmd.length == 1) { - System.out - .println("Sorry, it seems like you forgot to input the start time. Please read instructions again"); + System.out.println("Start time missing. Please read instructions again"); printInstructions(); } else { String startTime = cmd[1].split(" /to ")[0]; @@ -70,7 +69,7 @@ public static void executeAddEvent(String s, int taskId, TaskManager listofItems } } - public static void main(String[] args) { + private static void printGreeting() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" @@ -82,6 +81,10 @@ public static void main(String[] args) { printHorizontalLine(); printInstructions(); printHorizontalLine(); + } + + public static void main(String[] args) { + printGreeting(); Scanner scanObj = new Scanner(System.in); TaskManager listofItems = new TaskManager(); String userCmd = scanObj.nextLine(); From af773e9cac2d1a06c2dc5fb21bcffc274705c494 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Mon, 6 Feb 2023 16:36:38 +0800 Subject: [PATCH 09/22] Fix error of not tracking Deadline and Event java files/ added toString methods in classes to make code neater --- .gitignore | 1 - src/main/java/Deadline.java | 24 ++++++++++++++++++++++++ src/main/java/Event.java | 28 ++++++++++++++++++++++++++++ src/main/java/Task.java | 12 ++++++++++-- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java diff --git a/.gitignore b/.gitignore index 0c9fc9f2b..fed856c0f 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,3 @@ src/main/java/Duke.class src/main/java/Task.class src/main/java/TaskManager.class *.class -*.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..0a316d905 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,24 @@ +public class Deadline extends Task { + protected String by; + + public Deadline(String name, boolean isDone, int taskId, String by) { + super(name, isDone, taskId); + this.by = by; + } + + public String toString() { + if(this.getIsDone() == true) { + return " [D][X]" + this.getName() + " (by: " + this.by + ")"; + } else { + return " [D][ ]" + this.getName() + " (by: " + this.by + ")"; + } + } + + public void print() { + if (this.isIsDone() == false) { + System.out.println((this.getTaskId() + 1) + "." + this.toString()); + } else { + System.out.println((this.getTaskId() + 1) + "." + this.toString()); + } + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..4768318e0 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,28 @@ +public class Event extends Task { + protected String startTime; + protected String finishTime; + + public Event(String name, boolean isDone, int taskId, String startTime, String finishTime) { + super(name, isDone, taskId); + this.startTime = startTime; + this.finishTime = finishTime; + } + + public String toString() { + if(this.getIsDone() == true) { + return " [E][X]" + this.getName() + " (from: " + this.startTime + + " to: " + this.finishTime + ")"; + } else { + return " [E][ ]" + this.getName() + " (from: " + this.startTime + + " to: " + this.finishTime + ")"; + } + } + + public void print() { + if (this.isIsDone() == false) { + System.out.println((this.getTaskId() + 1) + "." + this.toString()); + } else { + System.out.println((this.getTaskId() + 1) + "." + this.toString()); + } + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index c6c12f293..6365ffcb1 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -50,11 +50,19 @@ public void setTaskId(int taskId) { this.taskId = taskId; } + public String toString() { + if(this.isDone == true) { + return " [T][X]" + this.name; + } else { + return " [T][ ]" + this.name; + } + } + public void print() { if (this.isDone == false) { - System.out.println((this.taskId + 1) + ".[T][ ] " + this.name); + System.out.println((this.taskId + 1) + "." + this.toString()); } else { - System.out.println((this.taskId + 1) + ".[T][X] " + this.name); + System.out.println((this.taskId + 1) + "." + this.toString()); } } } From 452032b827915a05af22a4589ed9290c456c68fd Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Mon, 6 Feb 2023 23:50:53 +0800 Subject: [PATCH 10/22] Added exceptions to catch error inputs --- src/main/java/Duke.java | 58 +++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 24bc0b14d..3abafc4fa 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,7 @@ import java.util.Scanner; +import javax.print.PrintException; + public class Duke { public static void printInstructions() { @@ -9,6 +11,8 @@ public static void printInstructions() { System.out.println( "event + \"event name\" + /from \"event start time\" + /to \"event finish time\" to add an event with a stant and finish time"); System.out.println("list to list all events and tasks available"); + System.out.println("mark + \"task number\" to mark a task"); + System.out.println("mark + \"task number\" to unmark a task"); } public static void printHorizontalLine() { @@ -29,43 +33,57 @@ public static String firstWord(String s) { } public static void executeAddTodo(String s, int taskId, TaskManager listofItems) { - s = s.substring("todo ".length(), s.length()); - listofItems.addTask(s, taskId); - System.out.println("Roger. The following todo has been added:"); - System.out.println("[T][ ] " + s); - System.out.println("You now have " + (taskId + 1) + " item in the list"); + try { + s = s.substring("todo ".length(), s.length()); + listofItems.addTask(s, taskId); + System.out.println("Roger. The following todo has been added:"); + System.out.println("[T][ ] " + s); + System.out.println("You now have " + (taskId + 1) + " item in the list"); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("Missing todo item. Please read instructions again"); + printInstructions(); + } } public static void executeAddDeadline(String s, int taskId, TaskManager listofItems) { - s = s.substring("deadline ".length(), s.length()); - String[] cmd = s.split(" /by "); - if (cmd.length == 1) { - System.out.println("Missing deadline. Please read instructions again"); - printInstructions(); - } else if (cmd.length > 2) { - System.out.println("Too many deadlines. Please read instructions again"); - printInstructions(); - } else { + try { + s = s.substring("deadline ".length(), s.length()); + String[] cmd = s.split(" /by "); + if (cmd.length > 2) { + System.out.println("Extra deadline found! Please try again!"); + printInstructions(); + return; + } listofItems.addDeadline(cmd[0], cmd[1], taskId); System.out.println("Roger. The following deadline has been added:"); System.out.println("[D][ ] " + cmd[0] + " (by: " + cmd[1] + ")"); System.out.println("You now have " + (taskId + 1) + " item in the list"); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("Your task name is missing please try again!"); + printInstructions(); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Your deadline is missing please try again!"); + printInstructions(); } + } public static void executeAddEvent(String s, int taskId, TaskManager listofItems) { - s = s.substring("event ".length(), s.length()); - String[] cmd = s.split(" /from "); - if (cmd.length == 1) { - System.out.println("Start time missing. Please read instructions again"); - printInstructions(); - } else { + try { + s = s.substring("event ".length(), s.length()); + String[] cmd = s.split(" /from "); String startTime = cmd[1].split(" /to ")[0]; String endTime = cmd[1].split(" /to ")[1]; listofItems.addEvent(cmd[0], startTime, endTime, taskId); System.out.println("Roger. The following event has been added:"); System.out.println("[E][ ] " + cmd[0] + " (from: " + startTime + " to: " + endTime + ")"); System.out.println("You now have " + (taskId + 1) + " item in the list"); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("Your task name is missing please try again!"); + printInstructions(); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Something is wrong with your event's start time or finish time please try again!"); + printInstructions(); } } From d47c75ddbd1452319e1e69a56495de6a5437f8c5 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Mon, 6 Feb 2023 23:58:37 +0800 Subject: [PATCH 11/22] Change the way Duke says goodbye --- src/main/java/Duke.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 24bc0b14d..f5e3e33bd 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -127,6 +127,9 @@ public static void main(String[] args) { userCmd = scanObj.nextLine(); } scanObj.close(); - System.out.println("Bye. Duke hopes to see you again soon !"); + System.out.println("Thanks for using Duke! See ya!"); + System.out.println(" /\\_/\\ "); + System.out.println("( o.o ) "); + System.out.println(" > ^ < "); } } From 4e75a59866dd85ba98535d91085a0953bdf9414f Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Tue, 7 Feb 2023 00:41:03 +0800 Subject: [PATCH 12/22] change the way Duke says goodbye --- src/main/java/Duke.java | 6 ++++-- src/main/java/Task.java | 1 + src/main/java/TaskManager.java | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 4f9b669d0..c4a490f71 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,7 +1,5 @@ import java.util.Scanner; -import javax.print.PrintException; - public class Duke { public static void printInstructions() { @@ -145,6 +143,10 @@ public static void main(String[] args) { userCmd = scanObj.nextLine(); } scanObj.close(); + printGoodbye(); + } + + private static void printGoodbye() { System.out.println("Thanks for using Duke! See ya!"); System.out.println(" /\\_/\\ "); System.out.println("( o.o ) "); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 6365ffcb1..1f956b2ea 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,3 +1,4 @@ + public class Task { private String name; private boolean isDone; diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java index adb23ff89..b605e36e7 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/TaskManager.java @@ -1,3 +1,5 @@ + + public class TaskManager { private Task[] tasks = new Task[100]; private int taskCount = 0; From 3cf14116c51a66651b770c54600ccdbdbd01e62e Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Tue, 7 Feb 2023 00:44:26 +0800 Subject: [PATCH 13/22] Create package called "Duke" to store all of the classes --- src/main/java/Duke.java | 3 +++ src/main/java/{ => duke}/Deadline.java | 1 + src/main/java/{ => duke}/Event.java | 1 + src/main/java/{ => duke}/Task.java | 1 + src/main/java/{ => duke}/TaskManager.java | 3 +-- 5 files changed, 7 insertions(+), 2 deletions(-) rename src/main/java/{ => duke}/Deadline.java (98%) rename src/main/java/{ => duke}/Event.java (98%) rename src/main/java/{ => duke}/Task.java (99%) rename src/main/java/{ => duke}/TaskManager.java (98%) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index c4a490f71..c9856cffb 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,5 +1,8 @@ + import java.util.Scanner; +import duke.TaskManager; + public class Duke { public static void printInstructions() { diff --git a/src/main/java/Deadline.java b/src/main/java/duke/Deadline.java similarity index 98% rename from src/main/java/Deadline.java rename to src/main/java/duke/Deadline.java index 0a316d905..2dc9b213b 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,3 +1,4 @@ +package duke; public class Deadline extends Task { protected String by; diff --git a/src/main/java/Event.java b/src/main/java/duke/Event.java similarity index 98% rename from src/main/java/Event.java rename to src/main/java/duke/Event.java index 4768318e0..e73cca854 100644 --- a/src/main/java/Event.java +++ b/src/main/java/duke/Event.java @@ -1,3 +1,4 @@ +package duke; public class Event extends Task { protected String startTime; protected String finishTime; diff --git a/src/main/java/Task.java b/src/main/java/duke/Task.java similarity index 99% rename from src/main/java/Task.java rename to src/main/java/duke/Task.java index 1f956b2ea..7c1e4ee10 100644 --- a/src/main/java/Task.java +++ b/src/main/java/duke/Task.java @@ -1,3 +1,4 @@ +package duke; public class Task { private String name; diff --git a/src/main/java/TaskManager.java b/src/main/java/duke/TaskManager.java similarity index 98% rename from src/main/java/TaskManager.java rename to src/main/java/duke/TaskManager.java index b605e36e7..391647b44 100644 --- a/src/main/java/TaskManager.java +++ b/src/main/java/duke/TaskManager.java @@ -1,5 +1,4 @@ - - +package duke; public class TaskManager { private Task[] tasks = new Task[100]; private int taskCount = 0; From c209898cc1987d4abfe3af446582bf8d85f1f1f6 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Mon, 27 Feb 2023 13:15:23 +0800 Subject: [PATCH 14/22] Changing names to comply with the coding standards --- src/main/java/Duke.java | 4 ++-- src/main/java/duke/Event.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index c9856cffb..bd84ff4e3 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -23,7 +23,7 @@ public static void printHorizontalLine() { System.out.println(); } - public static void falseInput() { + public static void printfalseInput() { System.out.println("Sorry Duke could not understand your input :> please follow the instructions"); printInstructions(); } @@ -140,7 +140,7 @@ public static void main(String[] args) { printHorizontalLine(); break; default: - falseInput(); + printfalseInput(); printHorizontalLine(); } userCmd = scanObj.nextLine(); diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java index e73cca854..878e6a00d 100644 --- a/src/main/java/duke/Event.java +++ b/src/main/java/duke/Event.java @@ -1,4 +1,5 @@ package duke; + public class Event extends Task { protected String startTime; protected String finishTime; @@ -10,13 +11,12 @@ public Event(String name, boolean isDone, int taskId, String startTime, String f } public String toString() { - if(this.getIsDone() == true) { + if (this.getIsDone() == true) { return " [E][X]" + this.getName() + " (from: " + this.startTime - + " to: " + this.finishTime + ")"; - } else { - return " [E][ ]" + this.getName() + " (from: " + this.startTime - + " to: " + this.finishTime + ")"; + + " to: " + this.finishTime + ")"; } + return " [E][ ]" + this.getName() + " (from: " + this.startTime + + " to: " + this.finishTime + ")"; } public void print() { From 894b7aa2deb6e665d9e5f4c3aa71b7507292317c Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Mon, 27 Feb 2023 15:30:37 +0800 Subject: [PATCH 15/22] Add the ability to remove tasks and implement using ArrayList --- src/main/java/Duke.java | 38 +++++++++++---------- src/main/java/duke/Deadline.java | 11 +++--- src/main/java/duke/Event.java | 8 ++--- src/main/java/duke/Task.java | 18 +++------- src/main/java/duke/TaskManager.java | 52 ++++++++++++++++++----------- 5 files changed, 67 insertions(+), 60 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index bd84ff4e3..8e5e9330c 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -12,8 +12,9 @@ public static void printInstructions() { System.out.println( "event + \"event name\" + /from \"event start time\" + /to \"event finish time\" to add an event with a stant and finish time"); System.out.println("list to list all events and tasks available"); - System.out.println("mark + \"task number\" to mark a task"); - System.out.println("mark + \"task number\" to unmark a task"); + System.out.println("mark + \"task number\" to mark an item"); + System.out.println("unmark + \"task number\" to unmark an item"); + System.out.println("delete + \"task number\" to remove an item"); } public static void printHorizontalLine() { @@ -33,20 +34,20 @@ public static String firstWord(String s) { return a[0]; } - public static void executeAddTodo(String s, int taskId, TaskManager listofItems) { + public static void executeAddTodo(String s, TaskManager listofItems) { try { s = s.substring("todo ".length(), s.length()); - listofItems.addTask(s, taskId); + listofItems.addTask(s); System.out.println("Roger. The following todo has been added:"); System.out.println("[T][ ] " + s); - System.out.println("You now have " + (taskId + 1) + " item in the list"); + System.out.println("You now have " + listofItems.getSize() + " item in the list"); } catch (StringIndexOutOfBoundsException e) { System.out.println("Missing todo item. Please read instructions again"); printInstructions(); } } - public static void executeAddDeadline(String s, int taskId, TaskManager listofItems) { + public static void executeAddDeadline(String s, TaskManager listofItems) { try { s = s.substring("deadline ".length(), s.length()); String[] cmd = s.split(" /by "); @@ -55,10 +56,10 @@ public static void executeAddDeadline(String s, int taskId, TaskManager listofIt printInstructions(); return; } - listofItems.addDeadline(cmd[0], cmd[1], taskId); + listofItems.addDeadline(cmd[0], cmd[1]); System.out.println("Roger. The following deadline has been added:"); System.out.println("[D][ ] " + cmd[0] + " (by: " + cmd[1] + ")"); - System.out.println("You now have " + (taskId + 1) + " item in the list"); + System.out.println("You now have " + listofItems.getSize() + " item in the list"); } catch (StringIndexOutOfBoundsException e) { System.out.println("Your task name is missing please try again!"); printInstructions(); @@ -69,16 +70,16 @@ public static void executeAddDeadline(String s, int taskId, TaskManager listofIt } - public static void executeAddEvent(String s, int taskId, TaskManager listofItems) { + public static void executeAddEvent(String s, TaskManager listofItems) { try { s = s.substring("event ".length(), s.length()); String[] cmd = s.split(" /from "); String startTime = cmd[1].split(" /to ")[0]; String endTime = cmd[1].split(" /to ")[1]; - listofItems.addEvent(cmd[0], startTime, endTime, taskId); + listofItems.addEvent(cmd[0], startTime, endTime); System.out.println("Roger. The following event has been added:"); System.out.println("[E][ ] " + cmd[0] + " (from: " + startTime + " to: " + endTime + ")"); - System.out.println("You now have " + (taskId + 1) + " item in the list"); + System.out.println("You now have " + listofItems.getSize() + " item in the list"); } catch (StringIndexOutOfBoundsException e) { System.out.println("Your task name is missing please try again!"); printInstructions(); @@ -107,23 +108,19 @@ public static void main(String[] args) { Scanner scanObj = new Scanner(System.in); TaskManager listofItems = new TaskManager(); String userCmd = scanObj.nextLine(); - int taskId = 0; while (!userCmd.equals("bye")) { switch (firstWord(userCmd)) { case "todo": - executeAddTodo(userCmd, taskId, listofItems); + executeAddTodo(userCmd, listofItems); printHorizontalLine(); - taskId++; break; case "deadline": - executeAddDeadline(userCmd, taskId, listofItems); + executeAddDeadline(userCmd, listofItems); printHorizontalLine(); - taskId++; break; case "event": - executeAddEvent(userCmd, taskId, listofItems); + executeAddEvent(userCmd, listofItems); printHorizontalLine(); - taskId++; break; case "list": listofItems.listTask(); @@ -139,6 +136,11 @@ public static void main(String[] args) { listofItems.unmarkTask(Integer.parseInt(unmarkId[1]) - 1); printHorizontalLine(); break; + case "delete": + String deleteId[] = userCmd.split(" "); + listofItems.deleteTask(Integer.parseInt(deleteId[1]) - 1); + printHorizontalLine(); + break; default: printfalseInput(); printHorizontalLine(); diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java index 2dc9b213b..d3bd1944a 100644 --- a/src/main/java/duke/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,14 +1,15 @@ package duke; + public class Deadline extends Task { protected String by; - public Deadline(String name, boolean isDone, int taskId, String by) { - super(name, isDone, taskId); + public Deadline(String name, boolean isDone, String by) { + super(name, isDone); this.by = by; } public String toString() { - if(this.getIsDone() == true) { + if (this.getIsDone() == true) { return " [D][X]" + this.getName() + " (by: " + this.by + ")"; } else { return " [D][ ]" + this.getName() + " (by: " + this.by + ")"; @@ -17,9 +18,9 @@ public String toString() { public void print() { if (this.isIsDone() == false) { - System.out.println((this.getTaskId() + 1) + "." + this.toString()); + System.out.println("." + this.toString()); } else { - System.out.println((this.getTaskId() + 1) + "." + this.toString()); + System.out.println("." + this.toString()); } } } diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java index 878e6a00d..3615a9e12 100644 --- a/src/main/java/duke/Event.java +++ b/src/main/java/duke/Event.java @@ -4,8 +4,8 @@ public class Event extends Task { protected String startTime; protected String finishTime; - public Event(String name, boolean isDone, int taskId, String startTime, String finishTime) { - super(name, isDone, taskId); + public Event(String name, boolean isDone, String startTime, String finishTime) { + super(name, isDone); this.startTime = startTime; this.finishTime = finishTime; } @@ -21,9 +21,9 @@ public String toString() { public void print() { if (this.isIsDone() == false) { - System.out.println((this.getTaskId() + 1) + "." + this.toString()); + System.out.println("." + this.toString()); } else { - System.out.println((this.getTaskId() + 1) + "." + this.toString()); + System.out.println("." + this.toString()); } } } diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java index 7c1e4ee10..de2903ef1 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/Task.java @@ -3,7 +3,6 @@ public class Task { private String name; private boolean isDone; - private int taskId; private char taskType; public boolean isIsDone() { @@ -18,10 +17,9 @@ public void setTaskType(char taskType) { this.taskType = taskType; } - public Task(String name, boolean isDone, int taskId) { + public Task(String name, boolean isDone) { this.name = name; this.isDone = isDone; - this.taskId = taskId; } public String getName() { @@ -44,16 +42,8 @@ public void setIsDone(boolean isDone) { this.isDone = isDone; } - public int getTaskId() { - return this.taskId; - } - - public void setTaskId(int taskId) { - this.taskId = taskId; - } - public String toString() { - if(this.isDone == true) { + if (this.isDone == true) { return " [T][X]" + this.name; } else { return " [T][ ]" + this.name; @@ -62,9 +52,9 @@ public String toString() { public void print() { if (this.isDone == false) { - System.out.println((this.taskId + 1) + "." + this.toString()); + System.out.println("." + this.toString()); } else { - System.out.println((this.taskId + 1) + "." + this.toString()); + System.out.println("." + this.toString()); } } } diff --git a/src/main/java/duke/TaskManager.java b/src/main/java/duke/TaskManager.java index 391647b44..649acde6b 100644 --- a/src/main/java/duke/TaskManager.java +++ b/src/main/java/duke/TaskManager.java @@ -1,38 +1,52 @@ package duke; + +import java.util.*; + public class TaskManager { - private Task[] tasks = new Task[100]; - private int taskCount = 0; + private ArrayList tasks = new ArrayList<>(); - public void addTask(String name, int id) { - tasks[taskCount] = new Task(name, false, id); - taskCount++; + public void addTask(String name) { + tasks.add(new Task(name, false)); } - public void addDeadline(String name, String deadline, int id) { - tasks[taskCount] = new Deadline(name, false, id, deadline); - taskCount++; + public void addDeadline(String name, String deadline) { + tasks.add(new Deadline(name, false,deadline)); } - public void addEvent(String eventName, String startTime, String finishTime, int id) { - tasks[taskCount] = new Event(eventName, false, id, startTime, finishTime); - taskCount++; + public void addEvent(String eventName, String startTime, String finishTime) { + tasks.add(new Event(eventName, false, startTime, finishTime)); } public void markTask(int id) { - tasks[id].setIsDone(true); - System.out.println("The task has been marked as done!"); - System.out.println("[X] " + tasks[id].getName()); + tasks.get(id).setIsDone(true); + System.out.println("This item has been marked as done!"); + System.out.println("[X] " + tasks.get(id).getName()); } public void unmarkTask(int id) { - tasks[id].setIsDone(false); - System.out.println("The task has been marked as NOT done!"); - System.out.println("[ ] " + tasks[id].getName()); + tasks.get(id).setIsDone(false); + System.out.println("The item has been marked as NOT done!"); + System.out.println("[ ] " + tasks.get(id).getName()); } public void listTask() { - for (int i = 0; i < taskCount; i++) { - tasks[i].print(); + if(tasks.size() == 0) { + System.out.println("The list is currently empty!"); + return; } + for (int i = 0; i < tasks.size(); i++) { + System.out.print(i + 1); + tasks.get(i).print(); + } + } + + public void deleteTask(int id) { + System.out.println("This item has been removed!"); + System.out.println("[ ] " + tasks.get(id).getName()); + tasks.remove(id); + } + + public int getSize() { + return tasks.size(); } } From dc3db0f19fefdf41786a6ec481f35c284d4c509e Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Tue, 28 Feb 2023 05:28:04 +0800 Subject: [PATCH 16/22] Add ability to write and read to harddrive --- src/main/java/Duke.java | 54 ++++++++++++++++++++++++++--- src/main/java/duke/Deadline.java | 19 ++++++++++ src/main/java/duke/Event.java | 19 ++++++++++ src/main/java/duke/Task.java | 21 ++++++++++- src/main/java/duke/TaskManager.java | 24 ++++++++++++- src/main/java/duke/load.txt | 4 +++ 6 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 src/main/java/duke/load.txt diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index bd84ff4e3..9d11f0b31 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,13 @@ import java.util.Scanner; +import java.io.IOException; +import java.io.File; +import java.io.FileNotFoundException; import duke.TaskManager; public class Duke { - + public static void printInstructions() { System.out.println("LIST OF ALL COMMANDS:"); System.out.println("todo + \"task name\" to add a task"); @@ -33,10 +36,10 @@ public static String firstWord(String s) { return a[0]; } - public static void executeAddTodo(String s, int taskId, TaskManager listofItems) { + public static void executeAddTodo(String s, int taskId, TaskManager listOfItems) { try { s = s.substring("todo ".length(), s.length()); - listofItems.addTask(s, taskId); + listOfItems.addTask(s, taskId); System.out.println("Roger. The following todo has been added:"); System.out.println("[T][ ] " + s); System.out.println("You now have " + (taskId + 1) + " item in the list"); @@ -102,7 +105,7 @@ private static void printGreeting() { printHorizontalLine(); } - public static void main(String[] args) { + public static void main(String[] args) throws IOException{ printGreeting(); Scanner scanObj = new Scanner(System.in); TaskManager listofItems = new TaskManager(); @@ -114,16 +117,19 @@ public static void main(String[] args) { executeAddTodo(userCmd, taskId, listofItems); printHorizontalLine(); taskId++; + listofItems.saveFile(); break; case "deadline": executeAddDeadline(userCmd, taskId, listofItems); printHorizontalLine(); taskId++; + listofItems.saveFile(); break; case "event": executeAddEvent(userCmd, taskId, listofItems); printHorizontalLine(); taskId++; + listofItems.saveFile(); break; case "list": listofItems.listTask(); @@ -133,11 +139,17 @@ public static void main(String[] args) { String markId[] = userCmd.split(" "); listofItems.markTask(Integer.parseInt(markId[1]) - 1); printHorizontalLine(); + listofItems.saveFile(); break; case "unmark": String unmarkId[] = userCmd.split(" "); listofItems.unmarkTask(Integer.parseInt(unmarkId[1]) - 1); printHorizontalLine(); + try { + listofItems.saveFile(); + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); + } break; default: printfalseInput(); @@ -149,6 +161,40 @@ public static void main(String[] args) { printGoodbye(); } + public void loadFile(TaskManager listOfItems) throws FileNotFoundException { + String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; + File f = new File(filePath); + Scanner s = new Scanner(f); + while (s.hasNext()) { + String l = s.nextLine(); + switch (l.substring(0,2)) { + case "[T]": + loadTodo(listOfItems, l); + break; + case "[D]": + loadDeadline(listOfItems, l); + break; + case "[E]": + loadEvent(listOfItems, l); + break; + default: + break; + } + } + s.close(); + } + + public void loadTodo(TaskManager listOfItems, String l) { + } + + public void loadEvent(TaskManager listOfItems, String l) { + + } + + public void loadDeadline(TaskManager listOfItems, String l) { + + } + private static void printGoodbye() { System.out.println("Thanks for using Duke! See ya!"); System.out.println(" /\\_/\\ "); diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java index 2dc9b213b..83d630ee1 100644 --- a/src/main/java/duke/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,4 +1,7 @@ package duke; + +import java.io.FileWriter; +import java.io.IOException; public class Deadline extends Task { protected String by; @@ -22,4 +25,20 @@ public void print() { System.out.println((this.getTaskId() + 1) + "." + this.toString()); } } + + private static void writeToFile(String filePath, String textToAdd) throws IOException { + FileWriter fw = new FileWriter(filePath); + fw.write(textToAdd); + fw.close(); + } + + public void save() { + String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; + try { + writeToFile(filePath, "D " + this.toString() + System.lineSeparator()); + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); + } + } + } diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java index 878e6a00d..329b8a463 100644 --- a/src/main/java/duke/Event.java +++ b/src/main/java/duke/Event.java @@ -1,5 +1,8 @@ package duke; +import java.io.FileWriter; +import java.io.IOException; + public class Event extends Task { protected String startTime; protected String finishTime; @@ -26,4 +29,20 @@ public void print() { System.out.println((this.getTaskId() + 1) + "." + this.toString()); } } + + private static void writeToFile(String filePath, String textToAdd) throws IOException { + FileWriter fw = new FileWriter(filePath); + fw.write(textToAdd); + fw.close(); + } + + public void save() { + String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; + try { + writeToFile(filePath, "E " + this.toString() + System.lineSeparator()); + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); + } + } + } diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java index 7c1e4ee10..0ea9922e1 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/Task.java @@ -1,5 +1,8 @@ package duke; +import java.io.FileWriter; +import java.io.IOException; + public class Task { private String name; private boolean isDone; @@ -53,7 +56,7 @@ public void setTaskId(int taskId) { } public String toString() { - if(this.isDone == true) { + if (this.isDone == true) { return " [T][X]" + this.name; } else { return " [T][ ]" + this.name; @@ -67,4 +70,20 @@ public void print() { System.out.println((this.taskId + 1) + "." + this.toString()); } } + + private static void writeToFile(String filePath, String textToAdd) throws IOException { + FileWriter fw = new FileWriter(filePath); + fw.write(textToAdd); + fw.close(); + } + + public void save() { + String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; + try { + writeToFile(filePath, "T " + this.toString() + System.lineSeparator()); + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); + } + } + } diff --git a/src/main/java/duke/TaskManager.java b/src/main/java/duke/TaskManager.java index 391647b44..672248a9f 100644 --- a/src/main/java/duke/TaskManager.java +++ b/src/main/java/duke/TaskManager.java @@ -1,6 +1,10 @@ package duke; + +import java.io.FileWriter; +import java.io.IOException; + public class TaskManager { - private Task[] tasks = new Task[100]; + private static Task[] tasks = new Task[100]; private int taskCount = 0; public void addTask(String name, int id) { @@ -8,6 +12,10 @@ public void addTask(String name, int id) { taskCount++; } + public int getTaskCount() { + return this.taskCount; + } + public void addDeadline(String name, String deadline, int id) { tasks[taskCount] = new Deadline(name, false, id, deadline); taskCount++; @@ -35,4 +43,18 @@ public void listTask() { tasks[i].print(); } } + + public void saveFile() throws IOException { + String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; + FileWriter fw = new FileWriter(filePath); + for (int i = 0; i < taskCount; i++) { + try { + fw.write(tasks[i].toString() + System.lineSeparator()); + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); + } + } + fw.close(); + } + } diff --git a/src/main/java/duke/load.txt b/src/main/java/duke/load.txt new file mode 100644 index 000000000..e85ae16eb --- /dev/null +++ b/src/main/java/duke/load.txt @@ -0,0 +1,4 @@ + [T][ ]this + [T][ ]that + [D][ ]those (by: tmr) + [E][ ]these (from: am to: pm) From 5fe873f1b54f53e3aa02bfb71141beb15b747716 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Tue, 28 Feb 2023 17:22:29 +0800 Subject: [PATCH 17/22] Add the ability to read and save data in a file called load.txt properly --- src/main/java/Duke.java | 64 ++++++++++++++++++++--------- src/main/java/duke/Deadline.java | 24 +---------- src/main/java/duke/Event.java | 23 +---------- src/main/java/duke/Task.java | 24 +---------- src/main/java/duke/TaskManager.java | 18 ++++---- src/main/java/duke/load.txt | 4 -- 6 files changed, 60 insertions(+), 97 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 2d6428cf2..9be4a4d5b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -7,7 +7,7 @@ import duke.TaskManager; public class Duke { - + public static void printInstructions() { System.out.println("LIST OF ALL COMMANDS:"); System.out.println("todo + \"task name\" to add a task"); @@ -18,6 +18,7 @@ public static void printInstructions() { System.out.println("mark + \"task number\" to mark an item"); System.out.println("unmark + \"task number\" to unmark an item"); System.out.println("delete + \"task number\" to remove an item"); + System.out.println("clear to clear all data in the hard drive"); } public static void printHorizontalLine() { @@ -40,7 +41,7 @@ public static String firstWord(String s) { public static void executeAddTodo(String s, TaskManager listofItems) { try { s = s.substring("todo ".length(), s.length()); - listofItems.addTask(s); + listofItems.addTask(s, false); System.out.println("Roger. The following todo has been added:"); System.out.println("[T][ ] " + s); System.out.println("You now have " + listofItems.getSize() + " item in the list"); @@ -59,7 +60,7 @@ public static void executeAddDeadline(String s, TaskManager listofItems) { printInstructions(); return; } - listofItems.addDeadline(cmd[0], cmd[1]); + listofItems.addDeadline(cmd[0], cmd[1], false); System.out.println("Roger. The following deadline has been added:"); System.out.println("[D][ ] " + cmd[0] + " (by: " + cmd[1] + ")"); System.out.println("You now have " + listofItems.getSize() + " item in the list"); @@ -79,7 +80,7 @@ public static void executeAddEvent(String s, TaskManager listofItems) { String[] cmd = s.split(" /from "); String startTime = cmd[1].split(" /to ")[0]; String endTime = cmd[1].split(" /to ")[1]; - listofItems.addEvent(cmd[0], startTime, endTime); + listofItems.addEvent(cmd[0], startTime, endTime, false); System.out.println("Roger. The following event has been added:"); System.out.println("[E][ ] " + cmd[0] + " (from: " + startTime + " to: " + endTime + ")"); System.out.println("You now have " + listofItems.getSize() + " item in the list"); @@ -106,10 +107,11 @@ private static void printGreeting() { printHorizontalLine(); } - public static void main(String[] args) throws IOException{ + public static void main(String[] args) throws IOException { printGreeting(); Scanner scanObj = new Scanner(System.in); TaskManager listofItems = new TaskManager(); + loadFile(listofItems); String userCmd = scanObj.nextLine(); while (!userCmd.equals("bye")) { switch (firstWord(userCmd)) { @@ -151,6 +153,11 @@ public static void main(String[] args) throws IOException{ printHorizontalLine(); listofItems.saveFile(); break; + case "clear": + listofItems.clearData(); + listofItems.saveFile(); + printHorizontalLine(); + break; default: printfalseInput(); printHorizontalLine(); @@ -161,38 +168,55 @@ public static void main(String[] args) throws IOException{ printGoodbye(); } - public void loadFile(TaskManager listOfItems) throws FileNotFoundException { + public static void loadFile(TaskManager listOfItems) throws FileNotFoundException { String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; File f = new File(filePath); Scanner s = new Scanner(f); while (s.hasNext()) { String l = s.nextLine(); - switch (l.substring(0,2)) { - case "[T]": + if (l.startsWith(" [T]")) { loadTodo(listOfItems, l); - break; - case "[D]": + } else if (l.startsWith(" [D]")) { loadDeadline(listOfItems, l); - break; - case "[E]": + } else if (l.startsWith(" [E]")) { loadEvent(listOfItems, l); - break; - default: - break; } } s.close(); } - public void loadTodo(TaskManager listOfItems, String l) { + public static void loadTodo(TaskManager listOfItems, String l) { + String name = l.substring(7).trim(); + if (l.contains("[ ]")) { + listOfItems.addTask(name, false); + } else { + listOfItems.addTask(name, true); + } } - public void loadEvent(TaskManager listOfItems, String l) { - + public static void loadEvent(TaskManager listOfItems, String l) { + int fromIndex = l.indexOf("(from: "); + int toIndex = l.indexOf(" to: ", fromIndex); + String name = l.substring(8, fromIndex).trim(); + String startTime = l.substring(fromIndex + 7, toIndex); + String finishTime = l.substring(toIndex + 5, l.length() - 1); + if (l.contains("[ ]")) { + listOfItems.addEvent(name, startTime, finishTime, false); + } else { + listOfItems.addEvent(name, startTime, finishTime, true); + } } - public void loadDeadline(TaskManager listOfItems, String l) { - + public static void loadDeadline(TaskManager listOfItems, String l) { + int byIndex = l.indexOf("(by: "); + String name = l.substring(8, byIndex - 1); + int endIndex = l.indexOf(")"); + String deadline = l.substring(byIndex + 5, endIndex); + if (l.contains("[ ]")) { + listOfItems.addDeadline(name, deadline, false); + } else { + listOfItems.addDeadline(name, deadline, true); + } } private static void printGoodbye() { diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java index 801a14821..6d1de287e 100644 --- a/src/main/java/duke/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,8 +1,5 @@ package duke; - -import java.io.FileWriter; -import java.io.IOException; public class Deadline extends Task { protected String by; @@ -13,10 +10,9 @@ public Deadline(String name, boolean isDone, String by) { public String toString() { if (this.getIsDone() == true) { - return " [D][X]" + this.getName() + " (by: " + this.by + ")"; - } else { - return " [D][ ]" + this.getName() + " (by: " + this.by + ")"; + return " [D][X] " + this.getName() + " (by: " + this.by + ")"; } + return " [D][ ] " + this.getName() + " (by: " + this.by + ")"; } public void print() { @@ -26,20 +22,4 @@ public void print() { System.out.println("." + this.toString()); } } - - private static void writeToFile(String filePath, String textToAdd) throws IOException { - FileWriter fw = new FileWriter(filePath); - fw.write(textToAdd); - fw.close(); - } - - public void save() { - String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; - try { - writeToFile(filePath, "D " + this.toString() + System.lineSeparator()); - } catch (IOException e) { - System.out.println("Something went wrong: " + e.getMessage()); - } - } - } diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java index 119b7f674..d922083ae 100644 --- a/src/main/java/duke/Event.java +++ b/src/main/java/duke/Event.java @@ -1,8 +1,5 @@ package duke; -import java.io.FileWriter; -import java.io.IOException; - public class Event extends Task { protected String startTime; protected String finishTime; @@ -15,10 +12,10 @@ public Event(String name, boolean isDone, String startTime, String finishTime) { public String toString() { if (this.getIsDone() == true) { - return " [E][X]" + this.getName() + " (from: " + this.startTime + return " [E][X] " + this.getName() + " (from: " + this.startTime + " to: " + this.finishTime + ")"; } - return " [E][ ]" + this.getName() + " (from: " + this.startTime + return " [E][ ] " + this.getName() + " (from: " + this.startTime + " to: " + this.finishTime + ")"; } @@ -29,20 +26,4 @@ public void print() { System.out.println("." + this.toString()); } } - - private static void writeToFile(String filePath, String textToAdd) throws IOException { - FileWriter fw = new FileWriter(filePath); - fw.write(textToAdd); - fw.close(); - } - - public void save() { - String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; - try { - writeToFile(filePath, "E " + this.toString() + System.lineSeparator()); - } catch (IOException e) { - System.out.println("Something went wrong: " + e.getMessage()); - } - } - } diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java index 87d1366fd..b00aea645 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/Task.java @@ -1,8 +1,5 @@ package duke; -import java.io.FileWriter; -import java.io.IOException; - public class Task { private String name; private boolean isDone; @@ -47,10 +44,9 @@ public void setIsDone(boolean isDone) { public String toString() { if (this.isDone == true) { - return " [T][X]" + this.name; - } else { - return " [T][ ]" + this.name; + return " [T][X] " + this.name; } + return " [T][ ] " + this.name; } public void print() { @@ -60,20 +56,4 @@ public void print() { System.out.println("." + this.toString()); } } - - private static void writeToFile(String filePath, String textToAdd) throws IOException { - FileWriter fw = new FileWriter(filePath); - fw.write(textToAdd); - fw.close(); - } - - public void save() { - String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; - try { - writeToFile(filePath, "T " + this.toString() + System.lineSeparator()); - } catch (IOException e) { - System.out.println("Something went wrong: " + e.getMessage()); - } - } - } diff --git a/src/main/java/duke/TaskManager.java b/src/main/java/duke/TaskManager.java index 50d35e47e..482156550 100644 --- a/src/main/java/duke/TaskManager.java +++ b/src/main/java/duke/TaskManager.java @@ -2,23 +2,22 @@ import java.util.*; - import java.io.FileWriter; import java.io.IOException; public class TaskManager { private ArrayList tasks = new ArrayList<>(); - public void addTask(String name) { - tasks.add(new Task(name, false)); + public void addTask(String name, boolean isDone) { + tasks.add(new Task(name, isDone)); } - public void addDeadline(String name, String deadline) { - tasks.add(new Deadline(name, false,deadline)); + public void addDeadline(String name, String deadline, boolean isDone) { + tasks.add(new Deadline(name, isDone, deadline)); } - public void addEvent(String eventName, String startTime, String finishTime) { - tasks.add(new Event(eventName, false, startTime, finishTime)); + public void addEvent(String eventName, String startTime, String finishTime, boolean isDone) { + tasks.add(new Event(eventName, isDone, startTime, finishTime)); } public void markTask(int id) { @@ -34,7 +33,7 @@ public void unmarkTask(int id) { } public void listTask() { - if(tasks.size() == 0) { + if (tasks.size() == 0) { System.out.println("The list is currently empty!"); return; } @@ -67,4 +66,7 @@ public void saveFile() throws IOException { fw.close(); } + public void clearData() { + tasks.clear(); + } } diff --git a/src/main/java/duke/load.txt b/src/main/java/duke/load.txt index e85ae16eb..e69de29bb 100644 --- a/src/main/java/duke/load.txt +++ b/src/main/java/duke/load.txt @@ -1,4 +0,0 @@ - [T][ ]this - [T][ ]that - [D][ ]those (by: tmr) - [E][ ]these (from: am to: pm) From 99531f82fd0d1748a398769519c7e22faa505614 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Wed, 1 Mar 2023 03:12:38 +0800 Subject: [PATCH 18/22] Create extra classes such that the project is more OOP - Parser, UI and Storage classes --- IP.jar | Bin 0 -> 9748 bytes src/main/java/Duke.java | 220 ++-------------------------- src/main/java/duke/Parser.java | 118 +++++++++++++++ src/main/java/duke/Storage.java | 79 ++++++++++ src/main/java/duke/TaskManager.java | 22 +-- src/main/java/duke/Ui.java | 51 +++++++ 6 files changed, 263 insertions(+), 227 deletions(-) create mode 100644 IP.jar create mode 100644 src/main/java/duke/Parser.java create mode 100644 src/main/java/duke/Storage.java create mode 100644 src/main/java/duke/Ui.java diff --git a/IP.jar b/IP.jar new file mode 100644 index 0000000000000000000000000000000000000000..89f980a2d06dff144c60c8600b790a0be3b764f3 GIT binary patch literal 9748 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 GZ~q64ozOr4 literal 0 HcmV?d00001 diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 9be4a4d5b..60eabf4f2 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,228 +1,26 @@ - import java.util.Scanner; import java.io.IOException; -import java.io.File; -import java.io.FileNotFoundException; +import duke.Parser; +import duke.Storage; import duke.TaskManager; +import duke.Ui; public class Duke { - public static void printInstructions() { - System.out.println("LIST OF ALL COMMANDS:"); - System.out.println("todo + \"task name\" to add a task"); - System.out.println("deadline + \"task name\" + /by \"task deadline\" to add a task with a deadline"); - System.out.println( - "event + \"event name\" + /from \"event start time\" + /to \"event finish time\" to add an event with a stant and finish time"); - System.out.println("list to list all events and tasks available"); - System.out.println("mark + \"task number\" to mark an item"); - System.out.println("unmark + \"task number\" to unmark an item"); - System.out.println("delete + \"task number\" to remove an item"); - System.out.println("clear to clear all data in the hard drive"); - } - - public static void printHorizontalLine() { - for (int i = 0; i <= 30; i++) { - System.out.print("_"); - } - System.out.println(); - } - - public static void printfalseInput() { - System.out.println("Sorry Duke could not understand your input :> please follow the instructions"); - printInstructions(); - } - - public static String firstWord(String s) { - String a[] = s.split(" "); - return a[0]; - } - - public static void executeAddTodo(String s, TaskManager listofItems) { - try { - s = s.substring("todo ".length(), s.length()); - listofItems.addTask(s, false); - System.out.println("Roger. The following todo has been added:"); - System.out.println("[T][ ] " + s); - System.out.println("You now have " + listofItems.getSize() + " item in the list"); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("Missing todo item. Please read instructions again"); - printInstructions(); - } - } - - public static void executeAddDeadline(String s, TaskManager listofItems) { - try { - s = s.substring("deadline ".length(), s.length()); - String[] cmd = s.split(" /by "); - if (cmd.length > 2) { - System.out.println("Extra deadline found! Please try again!"); - printInstructions(); - return; - } - listofItems.addDeadline(cmd[0], cmd[1], false); - System.out.println("Roger. The following deadline has been added:"); - System.out.println("[D][ ] " + cmd[0] + " (by: " + cmd[1] + ")"); - System.out.println("You now have " + listofItems.getSize() + " item in the list"); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("Your task name is missing please try again!"); - printInstructions(); - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Your deadline is missing please try again!"); - printInstructions(); - } - - } - - public static void executeAddEvent(String s, TaskManager listofItems) { - try { - s = s.substring("event ".length(), s.length()); - String[] cmd = s.split(" /from "); - String startTime = cmd[1].split(" /to ")[0]; - String endTime = cmd[1].split(" /to ")[1]; - listofItems.addEvent(cmd[0], startTime, endTime, false); - System.out.println("Roger. The following event has been added:"); - System.out.println("[E][ ] " + cmd[0] + " (from: " + startTime + " to: " + endTime + ")"); - System.out.println("You now have " + listofItems.getSize() + " item in the list"); - } catch (StringIndexOutOfBoundsException e) { - System.out.println("Your task name is missing please try again!"); - printInstructions(); - } catch (ArrayIndexOutOfBoundsException e) { - System.out.println("Something is wrong with your event's start time or finish time please try again!"); - printInstructions(); - } - } - - private static void printGreeting() { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("Hello! I'm Duke"); - System.out.println("What can I do for you ?"); - printHorizontalLine(); - printInstructions(); - printHorizontalLine(); - } - public static void main(String[] args) throws IOException { - printGreeting(); + Ui ui = new Ui(); + ui.printGreeting(); Scanner scanObj = new Scanner(System.in); - TaskManager listofItems = new TaskManager(); - loadFile(listofItems); + TaskManager listOfItems = new TaskManager(); + listOfItems = Storage.loadFile(listOfItems); String userCmd = scanObj.nextLine(); while (!userCmd.equals("bye")) { - switch (firstWord(userCmd)) { - case "todo": - executeAddTodo(userCmd, listofItems); - printHorizontalLine(); - listofItems.saveFile(); - break; - case "deadline": - executeAddDeadline(userCmd, listofItems); - printHorizontalLine(); - listofItems.saveFile(); - break; - case "event": - executeAddEvent(userCmd, listofItems); - printHorizontalLine(); - listofItems.saveFile(); - break; - case "list": - listofItems.listTask(); - printHorizontalLine(); - listofItems.saveFile(); - break; - case "mark": - String markId[] = userCmd.split(" "); - listofItems.markTask(Integer.parseInt(markId[1]) - 1); - printHorizontalLine(); - listofItems.saveFile(); - break; - case "unmark": - String unmarkId[] = userCmd.split(" "); - listofItems.unmarkTask(Integer.parseInt(unmarkId[1]) - 1); - printHorizontalLine(); - listofItems.saveFile(); - break; - case "delete": - String deleteId[] = userCmd.split(" "); - listofItems.deleteTask(Integer.parseInt(deleteId[1]) - 1); - printHorizontalLine(); - listofItems.saveFile(); - break; - case "clear": - listofItems.clearData(); - listofItems.saveFile(); - printHorizontalLine(); - break; - default: - printfalseInput(); - printHorizontalLine(); - } + Parser.handleCmd(userCmd, listOfItems, ui); userCmd = scanObj.nextLine(); } scanObj.close(); - printGoodbye(); + ui.printGoodbye(); } - public static void loadFile(TaskManager listOfItems) throws FileNotFoundException { - String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; - File f = new File(filePath); - Scanner s = new Scanner(f); - while (s.hasNext()) { - String l = s.nextLine(); - if (l.startsWith(" [T]")) { - loadTodo(listOfItems, l); - } else if (l.startsWith(" [D]")) { - loadDeadline(listOfItems, l); - } else if (l.startsWith(" [E]")) { - loadEvent(listOfItems, l); - } - } - s.close(); - } - - public static void loadTodo(TaskManager listOfItems, String l) { - String name = l.substring(7).trim(); - if (l.contains("[ ]")) { - listOfItems.addTask(name, false); - } else { - listOfItems.addTask(name, true); - } - } - - public static void loadEvent(TaskManager listOfItems, String l) { - int fromIndex = l.indexOf("(from: "); - int toIndex = l.indexOf(" to: ", fromIndex); - String name = l.substring(8, fromIndex).trim(); - String startTime = l.substring(fromIndex + 7, toIndex); - String finishTime = l.substring(toIndex + 5, l.length() - 1); - if (l.contains("[ ]")) { - listOfItems.addEvent(name, startTime, finishTime, false); - } else { - listOfItems.addEvent(name, startTime, finishTime, true); - } - } - - public static void loadDeadline(TaskManager listOfItems, String l) { - int byIndex = l.indexOf("(by: "); - String name = l.substring(8, byIndex - 1); - int endIndex = l.indexOf(")"); - String deadline = l.substring(byIndex + 5, endIndex); - if (l.contains("[ ]")) { - listOfItems.addDeadline(name, deadline, false); - } else { - listOfItems.addDeadline(name, deadline, true); - } - } - - private static void printGoodbye() { - System.out.println("Thanks for using Duke! See ya!"); - System.out.println(" /\\_/\\ "); - System.out.println("( o.o ) "); - System.out.println(" > ^ < "); - } } diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java new file mode 100644 index 000000000..44c41ed64 --- /dev/null +++ b/src/main/java/duke/Parser.java @@ -0,0 +1,118 @@ +package duke; + +import java.io.IOException; + +public class Parser { + + public static void handleCmd(String userCmd, TaskManager listOfItems, Ui ui) throws IOException{ + switch (firstWord(userCmd)) { + case "todo": + executeAddTodo(userCmd, listOfItems, ui); + ui.printHorizontalLine(); + Storage.saveFile(listOfItems); + break; + case "deadline": + executeAddDeadline(userCmd, listOfItems, ui); + ui.printHorizontalLine(); + Storage.saveFile(listOfItems); + break; + case "event": + executeAddEvent(userCmd, listOfItems, ui); + ui.printHorizontalLine(); + Storage.saveFile(listOfItems); + break; + case "list": + listOfItems.listTask(); + ui.printHorizontalLine(); + Storage.saveFile(listOfItems); + break; + case "mark": + String markId[] = userCmd.split(" "); + listOfItems.markTask(Integer.parseInt(markId[1]) - 1); + ui.printHorizontalLine(); + Storage.saveFile(listOfItems); + break; + case "unmark": + String unmarkId[] = userCmd.split(" "); + listOfItems.unmarkTask(Integer.parseInt(unmarkId[1]) - 1); + ui.printHorizontalLine(); + Storage.saveFile(listOfItems); + break; + case "delete": + String deleteId[] = userCmd.split(" "); + listOfItems.deleteTask(Integer.parseInt(deleteId[1]) - 1); + ui.printHorizontalLine(); + Storage.saveFile(listOfItems); + break; + case "clear": + listOfItems.clearData(); + Storage.saveFile(listOfItems); + ui.printHorizontalLine(); + break; + default: + ui.printfalseInput(); + ui.printHorizontalLine(); + } + } + + public static String firstWord(String s) { + String a[] = s.split(" "); + return a[0]; + } + + public static void executeAddTodo(String s, TaskManager listOfItems, Ui ui) { + try { + s = s.substring("todo ".length(), s.length()); + listOfItems.addTask(s, false); + System.out.println("Roger. The following todo has been added:"); + System.out.println("[T][ ] " + s); + System.out.println("You now have " + listOfItems.getSize() + " item in the list"); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("Missing todo item. Please read instructions again"); + ui.printInstructions(); + } + } + + public static void executeAddDeadline(String s, TaskManager listOfItems, Ui ui) { + try { + s = s.substring("deadline ".length(), s.length()); + String[] cmd = s.split(" /by "); + if (cmd.length > 2) { + System.out.println("Extra deadline found! Please try again!"); + ui.printInstructions(); + return; + } + listOfItems.addDeadline(cmd[0], cmd[1], false); + System.out.println("Roger. The following deadline has been added:"); + System.out.println("[D][ ] " + cmd[0] + " (by: " + cmd[1] + ")"); + System.out.println("You now have " + listOfItems.getSize() + " item in the list"); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("Your task name is missing please try again!"); + ui.printInstructions(); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Your deadline is missing please try again!"); + ui.printInstructions(); + } + + } + + public static void executeAddEvent(String s, TaskManager listOfItems, Ui ui) { + try { + s = s.substring("event ".length(), s.length()); + String[] cmd = s.split(" /from "); + String startTime = cmd[1].split(" /to ")[0]; + String endTime = cmd[1].split(" /to ")[1]; + listOfItems.addEvent(cmd[0], startTime, endTime, false); + System.out.println("Roger. The following event has been added:"); + System.out.println("[E][ ] " + cmd[0] + " (from: " + startTime + " to: " + endTime + ")"); + System.out.println("You now have " + listOfItems.getSize() + " item in the list"); + } catch (StringIndexOutOfBoundsException e) { + System.out.println("Your task name is missing please try again!"); + ui.printInstructions(); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("Something is wrong with your event's start time or finish time please try again!"); + ui.printInstructions(); + } + } + +} diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java new file mode 100644 index 000000000..a9e8af10a --- /dev/null +++ b/src/main/java/duke/Storage.java @@ -0,0 +1,79 @@ +package duke; + +import java.util.Scanner; +import java.io.IOException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; + +public class Storage extends TaskManager { + + public static TaskManager loadFile(TaskManager listOfItems) throws FileNotFoundException { + String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; + File f = new File(filePath); + if (!f.exists()) { + throw new FileNotFoundException(); + } + Scanner s = new Scanner(f); + while (s.hasNext()) { + String l = s.nextLine(); + if (l.startsWith(" [T]")) { + loadTodo(listOfItems, l); + } else if (l.startsWith(" [D]")) { + loadDeadline(listOfItems, l); + } else if (l.startsWith(" [E]")) { + loadEvent(listOfItems, l); + } + } + s.close(); + return listOfItems; + } + + public static void loadTodo(TaskManager listOfItems, String l) { + String name = l.substring(7).trim(); + if (l.contains("[ ]")) { + listOfItems.addTask(name, false); + } else { + listOfItems.addTask(name, true); + } + } + + public static void loadEvent(TaskManager listOfItems, String l) { + int fromIndex = l.indexOf("(from: "); + int toIndex = l.indexOf(" to: ", fromIndex); + String name = l.substring(8, fromIndex).trim(); + String startTime = l.substring(fromIndex + 7, toIndex); + String finishTime = l.substring(toIndex + 5, l.length() - 1); + if (l.contains("[ ]")) { + listOfItems.addEvent(name, startTime, finishTime, false); + } else { + listOfItems.addEvent(name, startTime, finishTime, true); + } + } + + public static void loadDeadline(TaskManager listOfItems, String l) { + int byIndex = l.indexOf("(by: "); + String name = l.substring(8, byIndex - 1); + int endIndex = l.indexOf(")"); + String deadline = l.substring(byIndex + 5, endIndex); + if (l.contains("[ ]")) { + listOfItems.addDeadline(name, deadline, false); + } else { + listOfItems.addDeadline(name, deadline, true); + } + } + + public static void saveFile(TaskManager listOfItems) throws IOException { + String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; + FileWriter fw = new FileWriter(filePath); + for (int i = 0; i < listOfItems.getSize(); i++) { + try { + fw.write(listOfItems.getId(i).toString() + System.lineSeparator()); + } catch (IOException e) { + System.out.println("Something went wrong: " + e.getMessage()); + } + } + fw.close(); + } + +} diff --git a/src/main/java/duke/TaskManager.java b/src/main/java/duke/TaskManager.java index 482156550..d01eb7565 100644 --- a/src/main/java/duke/TaskManager.java +++ b/src/main/java/duke/TaskManager.java @@ -2,9 +2,6 @@ import java.util.*; -import java.io.FileWriter; -import java.io.IOException; - public class TaskManager { private ArrayList tasks = new ArrayList<>(); @@ -53,20 +50,13 @@ public int getSize() { return tasks.size(); } - public void saveFile() throws IOException { - String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; - FileWriter fw = new FileWriter(filePath); - for (int i = 0; i < tasks.size(); i++) { - try { - fw.write(tasks.get(i).toString() + System.lineSeparator()); - } catch (IOException e) { - System.out.println("Something went wrong: " + e.getMessage()); - } - } - fw.close(); - } - public void clearData() { tasks.clear(); + System.out.println("Your list has been cleared !"); + } + + public Task getId(int id) { + return tasks.get(id); } + } diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java new file mode 100644 index 000000000..1ab721fa9 --- /dev/null +++ b/src/main/java/duke/Ui.java @@ -0,0 +1,51 @@ +package duke; + +public class Ui { + + public void printInstructions() { + System.out.println("LIST OF ALL COMMANDS:"); + System.out.println("todo + \"task name\" to add a task"); + System.out.println("deadline + \"task name\" + /by \"task deadline\" to add a task with a deadline"); + System.out.println( + "event + \"event name\" + /from \"event start time\" + /to \"event finish time\" to add an event with a stant and finish time"); + System.out.println("list to list all events and tasks available"); + System.out.println("mark + \"task number\" to mark an item"); + System.out.println("unmark + \"task number\" to unmark an item"); + System.out.println("delete + \"task number\" to remove an item"); + System.out.println("clear to clear all data in the hard drive"); + } + + public void printHorizontalLine() { + for (int i = 0; i <= 30; i++) { + System.out.print("_"); + } + System.out.println(); + } + + public void printfalseInput() { + System.out.println("Sorry Duke could not understand your input :> please follow the instructions"); + printInstructions(); + } + + public void printGreeting() { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you ?"); + printHorizontalLine(); + printInstructions(); + printHorizontalLine(); + } + + public void printGoodbye() { + System.out.println("Thanks for using Duke! See ya!"); + System.out.println(" /\\_/\\ "); + System.out.println("( o.o ) "); + System.out.println(" > ^ < "); + } + +} From 21db370a761d0d211b08418b24f01aa01d5bd3c5 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Wed, 1 Mar 2023 03:31:45 +0800 Subject: [PATCH 19/22] Add the ability to find task --- src/main/java/duke/Parser.java | 10 +++++++--- src/main/java/duke/Task.java | 5 +++++ src/main/java/duke/TaskManager.java | 17 +++++++++++++++++ src/main/java/duke/Ui.java | 1 + src/main/java/duke/load.txt | 3 +++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index 44c41ed64..e2f8b31da 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -3,8 +3,8 @@ import java.io.IOException; public class Parser { - - public static void handleCmd(String userCmd, TaskManager listOfItems, Ui ui) throws IOException{ + + public static void handleCmd(String userCmd, TaskManager listOfItems, Ui ui) throws IOException { switch (firstWord(userCmd)) { case "todo": executeAddTodo(userCmd, listOfItems, ui); @@ -49,6 +49,10 @@ public static void handleCmd(String userCmd, TaskManager listOfItems, Ui ui) thr Storage.saveFile(listOfItems); ui.printHorizontalLine(); break; + case "find": + listOfItems.findItem(userCmd.substring(5, userCmd.length())); + ui.printHorizontalLine(); + break; default: ui.printfalseInput(); ui.printHorizontalLine(); @@ -114,5 +118,5 @@ public static void executeAddEvent(String s, TaskManager listOfItems, Ui ui) { ui.printInstructions(); } } - + } diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java index b00aea645..0ecca6f71 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/Task.java @@ -56,4 +56,9 @@ public void print() { System.out.println("." + this.toString()); } } + + public boolean find(String s) { + return this.name.contains(s); + } + } diff --git a/src/main/java/duke/TaskManager.java b/src/main/java/duke/TaskManager.java index d01eb7565..1920ba615 100644 --- a/src/main/java/duke/TaskManager.java +++ b/src/main/java/duke/TaskManager.java @@ -5,6 +5,23 @@ public class TaskManager { private ArrayList tasks = new ArrayList<>(); + public void findItem(String s) { + boolean found = false; + if (tasks.size() == 0) { + System.out.println("The list is currently empty!"); + return; + } + for (int i = 0; i < tasks.size(); i++) { + if (tasks.get(i).find(s)) { + System.out.println("Item found: " + (i + 1) + "." + tasks.get(i).toString()); + found = true; + } + } + if (found == false) { + System.out.println("Sorry there is no match for your search !"); + } + } + public void addTask(String name, boolean isDone) { tasks.add(new Task(name, isDone)); } diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 1ab721fa9..63bc2013f 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -13,6 +13,7 @@ public void printInstructions() { System.out.println("unmark + \"task number\" to unmark an item"); System.out.println("delete + \"task number\" to remove an item"); System.out.println("clear to clear all data in the hard drive"); + System.out.println("find + \"phrase\" to find an item containing the phrase"); } public void printHorizontalLine() { diff --git a/src/main/java/duke/load.txt b/src/main/java/duke/load.txt index e69de29bb..0f5965f8c 100644 --- a/src/main/java/duke/load.txt +++ b/src/main/java/duke/load.txt @@ -0,0 +1,3 @@ + [T][ ] this + [T][ ] that + [T][ ] wut From 08da801094fd53e0b6489e30d361b48a93d93c0c Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Fri, 3 Mar 2023 02:24:35 +0800 Subject: [PATCH 20/22] Add documentation --- src/main/java/Duke.java | 4 +- src/main/java/duke/Deadline.java | 20 +++++++++ src/main/java/duke/Event.java | 24 +++++++++++ src/main/java/duke/Parser.java | 39 +++++++++++++++++ src/main/java/duke/Storage.java | 36 ++++++++++++++++ src/main/java/duke/Task.java | 66 +++++++++++++++++++++++++++++ src/main/java/duke/TaskManager.java | 65 ++++++++++++++++++++++++++++ src/main/java/duke/Ui.java | 20 ++++++++- 8 files changed, 272 insertions(+), 2 deletions(-) diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 60eabf4f2..b3bff38c4 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -6,8 +6,10 @@ import duke.TaskManager; import duke.Ui; +/** + * Duke main class. This is the entry point for the Duke program. + */ public class Duke { - public static void main(String[] args) throws IOException { Ui ui = new Ui(); ui.printGreeting(); diff --git a/src/main/java/duke/Deadline.java b/src/main/java/duke/Deadline.java index 6d1de287e..70287625e 100644 --- a/src/main/java/duke/Deadline.java +++ b/src/main/java/duke/Deadline.java @@ -1,13 +1,29 @@ package duke; +/** + * Represents a Deadline task with a specific due date. + * Inherits from the Task class. + */ public class Deadline extends Task { protected String by; + /** + * Constructor for the Deadline class. + * + * @param name the name of the deadline task + * @param isDone whether the task is marked as done or not + * @param by the due date of the task + */ public Deadline(String name, boolean isDone, String by) { super(name, isDone); this.by = by; } + /** + * Overrides the toString method to display the task's details as a string. + * + * @return a formatted string representation of the task's details + */ public String toString() { if (this.getIsDone() == true) { return " [D][X] " + this.getName() + " (by: " + this.by + ")"; @@ -15,6 +31,9 @@ public String toString() { return " [D][ ] " + this.getName() + " (by: " + this.by + ")"; } + /** + * Overrides the print method to print the task details in a specific format. + */ public void print() { if (this.isIsDone() == false) { System.out.println("." + this.toString()); @@ -22,4 +41,5 @@ public void print() { System.out.println("." + this.toString()); } } + } diff --git a/src/main/java/duke/Event.java b/src/main/java/duke/Event.java index d922083ae..345f49a1d 100644 --- a/src/main/java/duke/Event.java +++ b/src/main/java/duke/Event.java @@ -1,15 +1,36 @@ package duke; +/** + * Event class represents an event task with a start time and a finish time. + * It extends the Task class and adds the startTime and finishTime attributes. + */ public class Event extends Task { protected String startTime; protected String finishTime; + /** + * Constructs an Event object with a name, completion status, start time, and + * finish time. + * + * @param name the name of the event task + * @param isDone the completion status of the event task + * @param startTime the start time of the event task + * @param finishTime the finish time of the event task + */ public Event(String name, boolean isDone, String startTime, String finishTime) { super(name, isDone); this.startTime = startTime; this.finishTime = finishTime; } + /** + * Returns a string representation of the event task with its completion status, + * name, start time, and finish time. + * If the task is completed, the completion status is marked with an 'X', + * otherwise it is marked with a space. + * + * @return a string representation of the event task + */ public String toString() { if (this.getIsDone() == true) { return " [E][X] " + this.getName() + " (from: " + this.startTime @@ -19,6 +40,9 @@ public String toString() { + " to: " + this.finishTime + ")"; } + /** + * Prints the string representation of the event task with a dot prefix. + */ public void print() { if (this.isIsDone() == false) { System.out.println("." + this.toString()); diff --git a/src/main/java/duke/Parser.java b/src/main/java/duke/Parser.java index e2f8b31da..8993f5117 100644 --- a/src/main/java/duke/Parser.java +++ b/src/main/java/duke/Parser.java @@ -2,8 +2,20 @@ import java.io.IOException; +/** + * The Parser class is responsible for parsing the user's input command and + * executing the corresponding actions. + */ public class Parser { + /** + * Parses the user's input command and executes the corresponding actions. + * + * @param userCmd the user's input command + * @param listOfItems the TaskManager that stores the user's tasks + * @param ui the Ui object that handles the program's output + * @throws IOException if an I/O error occurs + */ public static void handleCmd(String userCmd, TaskManager listOfItems, Ui ui) throws IOException { switch (firstWord(userCmd)) { case "todo": @@ -59,11 +71,24 @@ public static void handleCmd(String userCmd, TaskManager listOfItems, Ui ui) thr } } + /** + * Returns the first word of a given string. + * + * @param s the string + * @return the first word of the string + */ public static String firstWord(String s) { String a[] = s.split(" "); return a[0]; } + /** + * Executes the "todo" command by adding a new Todo task to the TaskManager. + * + * @param s the user's input command + * @param listOfItems the TaskManager that stores the user's tasks + * @param ui the Ui object that handles the program's output + */ public static void executeAddTodo(String s, TaskManager listOfItems, Ui ui) { try { s = s.substring("todo ".length(), s.length()); @@ -77,6 +102,13 @@ public static void executeAddTodo(String s, TaskManager listOfItems, Ui ui) { } } + /** + * Adds a new Deadline task to the list of tasks. + * + * @param s The string representation of the task to be added. + * @param listOfItems The TaskManager object that holds the list of tasks. + * @param ui The UI object that interacts with the user. + */ public static void executeAddDeadline(String s, TaskManager listOfItems, Ui ui) { try { s = s.substring("deadline ".length(), s.length()); @@ -100,6 +132,13 @@ public static void executeAddDeadline(String s, TaskManager listOfItems, Ui ui) } + /** + * Adds a new Event task to the list of tasks. + * + * @param s The string representation of the task to be added. + * @param listOfItems The TaskManager object that holds the list of tasks. + * @param ui The UI object that interacts with the user. + */ public static void executeAddEvent(String s, TaskManager listOfItems, Ui ui) { try { s = s.substring("event ".length(), s.length()); diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index a9e8af10a..b520f30a8 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -6,8 +6,18 @@ import java.io.FileNotFoundException; import java.io.FileWriter; +/** + * Storage class deals with saving and loading TaskManager class. + */ public class Storage extends TaskManager { + /** + * Loads data from a file into the given TaskManager object. + * + * @param listOfItems The TaskManager object to load the data into. + * @return The TaskManager object with the loaded data. + * @throws FileNotFoundException If the file to load from is not found. + */ public static TaskManager loadFile(TaskManager listOfItems) throws FileNotFoundException { String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; File f = new File(filePath); @@ -29,6 +39,12 @@ public static TaskManager loadFile(TaskManager listOfItems) throws FileNotFoundE return listOfItems; } + /** + * Loads a Todo item from a string and adds it to the given TaskManager object. + * + * @param listOfItems The TaskManager object to add the Todo item to. + * @param l he string containing the Todo item details. + */ public static void loadTodo(TaskManager listOfItems, String l) { String name = l.substring(7).trim(); if (l.contains("[ ]")) { @@ -38,6 +54,13 @@ public static void loadTodo(TaskManager listOfItems, String l) { } } + /** + * Loads an Event item from a string and adds it to the given TaskManager + * object. + * + * @param listOfItems The TaskManager object to add the Event item to. + * @param l The string containing the Event item details. + */ public static void loadEvent(TaskManager listOfItems, String l) { int fromIndex = l.indexOf("(from: "); int toIndex = l.indexOf(" to: ", fromIndex); @@ -51,6 +74,13 @@ public static void loadEvent(TaskManager listOfItems, String l) { } } + /** + * Loads a Deadline item from a string and adds it to the given TaskManager + * object. + * + * @param listOfItems The TaskManager object to add the Deadline item to. + * @param l The string containing the Deadline item details. + */ public static void loadDeadline(TaskManager listOfItems, String l) { int byIndex = l.indexOf("(by: "); String name = l.substring(8, byIndex - 1); @@ -63,6 +93,12 @@ public static void loadDeadline(TaskManager listOfItems, String l) { } } + /** + * Save the TaskManager object into the harddrive. + * + * @param listOfItems The TaskManager object + * @throws IOException If there is something wrong with saving the file + */ public static void saveFile(TaskManager listOfItems) throws IOException { String filePath = "C:/repos/IP/src/main/java/duke/load.txt"; FileWriter fw = new FileWriter(filePath); diff --git a/src/main/java/duke/Task.java b/src/main/java/duke/Task.java index 0ecca6f71..a3ff85b51 100644 --- a/src/main/java/duke/Task.java +++ b/src/main/java/duke/Task.java @@ -1,47 +1,102 @@ package duke; +/* +The Task class represents a task with a name, a completion status, and a task type. +*/ public class Task { private String name; private boolean isDone; private char taskType; + /** + * Returns the completion status of the task. + * + * @return a boolean representing the completion status of the task. + */ public boolean isIsDone() { return this.isDone; } + /** + * Returns the type of the task. + * + * @return a char representing the type of the task. + */ public char getTaskType() { return this.taskType; } + /* + * Sets the type of the task. + * + * @param taskType a char representing the type of the task. + */ public void setTaskType(char taskType) { this.taskType = taskType; } + /* + * Creates a new task with a given name and completion status. + * + * @param name a String representing the name of the task. + * + * @param isDone a boolean representing the completion status of the task. + */ public Task(String name, boolean isDone) { this.name = name; this.isDone = isDone; } + /** + * Returns the name of the task. + * + * @return a String representing the name of the task. + */ public String getName() { return this.name; } + /** + * Sets the name of the task. + * + * @param name a String representing the name of the task. + */ public void setName(String name) { this.name = name; } + /** + * Returns the completion status of the task. + * + * @return a boolean representing the completion status of the task. + */ public boolean isDone() { return this.isDone; } + /** + * Returns the completion status of the task. + * + * @return a boolean representing the completion status of the task. + */ public boolean getIsDone() { return this.isDone; } + /** + * Sets the completion status of the task. + * + * @param isDone a boolean representing the completion status of the task. + */ public void setIsDone(boolean isDone) { this.isDone = isDone; } + /** + * Returns a String representation of the task. + * + * @return a String representing the task. + */ public String toString() { if (this.isDone == true) { return " [T][X] " + this.name; @@ -49,6 +104,9 @@ public String toString() { return " [T][ ] " + this.name; } + /** + * Prints the task to the console. + */ public void print() { if (this.isDone == false) { System.out.println("." + this.toString()); @@ -57,6 +115,14 @@ public void print() { } } + /** + * Searches the name of the task for a given String. + * + * @param s a String representing the search query. + * + * @return a boolean indicating whether the search query was found in the name + * of the task. + */ public boolean find(String s) { return this.name.contains(s); } diff --git a/src/main/java/duke/TaskManager.java b/src/main/java/duke/TaskManager.java index 1920ba615..440b17757 100644 --- a/src/main/java/duke/TaskManager.java +++ b/src/main/java/duke/TaskManager.java @@ -2,9 +2,19 @@ import java.util.*; +/** + * This class represents a task manager that stores and manages tasks. + */ public class TaskManager { private ArrayList tasks = new ArrayList<>(); + /** + * Finds a task in the list of tasks that contains the given string. + * If a matching task is found, its details are printed. + * If no matching task is found, a message is printed. + * + * @param s The string to search for in the task names. + */ public void findItem(String s) { boolean found = false; if (tasks.size() == 0) { @@ -22,30 +32,66 @@ public void findItem(String s) { } } + /** + * Adds a task with the given name and completion status to the list of tasks. + * + * @param name The name of the task. + * @param isDone The completion status of the task. + */ public void addTask(String name, boolean isDone) { tasks.add(new Task(name, isDone)); } + /** + * Adds a deadline with the given name, completion status, and deadline string + * to the list of tasks. + * + * @param name The name of the deadline. + * @param deadline The deadline string. + * @param isDone The completion status of the deadline. + */ public void addDeadline(String name, String deadline, boolean isDone) { tasks.add(new Deadline(name, isDone, deadline)); } + /** + * Adds an event with the given name, start time, finish time, and completion + * status to the list of tasks. + * + * @param eventName The name of the event. + * @param startTime The start time string. + * @param finishTime The finish time string. + * @param isDone The completion status of the event. + */ public void addEvent(String eventName, String startTime, String finishTime, boolean isDone) { tasks.add(new Event(eventName, isDone, startTime, finishTime)); } + /** + * Marks the task with the given ID as done. + * + * @param id The ID of the task to mark as done. + */ public void markTask(int id) { tasks.get(id).setIsDone(true); System.out.println("This item has been marked as done!"); System.out.println("[X] " + tasks.get(id).getName()); } + /** + * Unmarks the task with the given ID as done. + * + * @param id The ID of the task to unmark as done. + */ public void unmarkTask(int id) { tasks.get(id).setIsDone(false); System.out.println("The item has been marked as NOT done!"); System.out.println("[ ] " + tasks.get(id).getName()); } + /** + * Lists all the tasks in the task manager. + */ public void listTask() { if (tasks.size() == 0) { System.out.println("The list is currently empty!"); @@ -57,21 +103,40 @@ public void listTask() { } } + /** + * Deletes a task at the specified index. + * + * @param id The index of the task to be deleted. + */ public void deleteTask(int id) { System.out.println("This item has been removed!"); System.out.println("[ ] " + tasks.get(id).getName()); tasks.remove(id); } + /** + * Gets the size of the task list. + * + * @return The size of the task list. + */ public int getSize() { return tasks.size(); } + /** + * Clears all tasks from the task list. + */ public void clearData() { tasks.clear(); System.out.println("Your list has been cleared !"); } + /** + * Gets the task at the specified index. + * + * @param id The index of the task to be retrieved. + * @return The task at the specified index. + */ public Task getId(int id) { return tasks.get(id); } diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 63bc2013f..f3a5a4f23 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -1,7 +1,13 @@ package duke; +/** + * This class manages the UI for Duke + */ public class Ui { - + /** + * Print the Input guidelines for the reader such that Duke understands the + * Input + */ public void printInstructions() { System.out.println("LIST OF ALL COMMANDS:"); System.out.println("todo + \"task name\" to add a task"); @@ -16,6 +22,9 @@ public void printInstructions() { System.out.println("find + \"phrase\" to find an item containing the phrase"); } + /** + * Print the Horizontal Line that seperates between different user Inputs + */ public void printHorizontalLine() { for (int i = 0; i <= 30; i++) { System.out.print("_"); @@ -23,11 +32,17 @@ public void printHorizontalLine() { System.out.println(); } + /** + * Print the message for user to signal that Duke cannot understand the input + */ public void printfalseInput() { System.out.println("Sorry Duke could not understand your input :> please follow the instructions"); printInstructions(); } + /** + * Print the Greeting when Duke is started + */ public void printGreeting() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -42,6 +57,9 @@ public void printGreeting() { printHorizontalLine(); } + /** + * Print the Goodbye message when user exits Duke + */ public void printGoodbye() { System.out.println("Thanks for using Duke! See ya!"); System.out.println(" /\\_/\\ "); From 1aaf326f46ec4e76162f54c6856b1d2b41ce5849 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Fri, 3 Mar 2023 02:35:24 +0800 Subject: [PATCH 21/22] no message --- src/main/java/duke/TaskManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/duke/TaskManager.java b/src/main/java/duke/TaskManager.java index d01eb7565..53430e318 100644 --- a/src/main/java/duke/TaskManager.java +++ b/src/main/java/duke/TaskManager.java @@ -41,7 +41,7 @@ public void listTask() { } public void deleteTask(int id) { - System.out.println("This item has been removed!"); + System.out.println("This item has been deleted!"); System.out.println("[ ] " + tasks.get(id).getName()); tasks.remove(id); } From c9abb2223373d872331708904c484913d37a0c63 Mon Sep 17 00:00:00 2001 From: QUANGANH Date: Fri, 3 Mar 2023 03:12:46 +0800 Subject: [PATCH 22/22] Updated the readme file --- docs/README.md | 139 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 124 insertions(+), 15 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8077118eb..e659f5aea 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,138 @@ -# User Guide +User Guide +Features +Adding a Todo Task +Add a new Todo task to the list of tasks. -## Features +Adding a Deadline Task +Add a new Deadline task to the list of tasks. -### Feature-ABC +Adding an Event Task +Add a new Event task to the list of tasks. -Description of the feature. +Listing all Tasks +List all the tasks in the TaskManager. -### Feature-XYZ +Marking a Task as Done +Mark a task in the TaskManager as done. -Description of the feature. +Unmarking a Task +Unmark a task in the TaskManager. -## Usage +Deleting a Task +Delete a task from the TaskManager. -### `Keyword` - Describe action +Clearing all Tasks +Clear all the tasks from the TaskManager. -Describe the action and its outcome. +Finding Tasks by Keyword +Find tasks in the TaskManager by a keyword. -Example of usage: +Usage +todo - Add a Todo task +Add a new Todo task to the list of tasks. -`keyword (optional arguments)` +Example of usage: + +todo read book + +Expected outcome: + +Roger. The following todo has been added: +[T][ ] read book +You now have 1 item in the list + +deadline - Add a Deadline task +Add a new Deadline task to the list of tasks. + +Example of usage: + +deadline return book /by Sunday + +Expected outcome: + +Roger. The following deadline has been added: +[D][ ] return book (by: Sunday) +You now have 1 item in the list + +event - Add an Event task +Add a new Event task to the list of tasks. + +Example of usage: + +event project meeting /at Monday 2pm + +Expected outcome: + +Roger. The following event has been added: +[E][ ] project meeting (at: Monday 2pm) +You now have 1 item in the list + +list - List all Tasks +List all the tasks in the TaskManager. + +Example of usage: + +list Expected outcome: -Description of the outcome. +Here are the tasks in your list: +1.[T][ ] read book +2.[D][ ] return book (by: Sunday) +3.[E][ ] project meeting (at: Monday 2pm) + +mark - Mark a Task as Done +Mark a task in the TaskManager as done. + +Example of usage: + +mark 2 + +Expected outcome: + +Nice! I've marked this task as done: +[D][X] return book (by: Sunday) + + +unmark - Unmark a Task +Unmark a task in the TaskManager. + +Example of usage: + +unmark 2 + +Expected outcome: + +Nice! I've unmarked this task: +[D][ ] return book (by: Sunday) +delete - Delete a Task +Delete a task from the TaskManager. + +Example of usage: + +delete 2 + +Expected outcome: + +Noted. I've removed this task: +[D][ ] return book (by: Sunday) + +Example of usage: + +clear + +Expected outcome: + +All data deleted. You have no items in your list. + +find - Find Tasks by Keyword +Find tasks in the TaskManager by a keyword. + +Example of usage: + +find book + +Expected outcome: -``` -expected output -``` +Here are the matching tasks in your list: +1.[T][ ] read book \ No newline at end of file