From a8435c7934e0ebcddd39ac378c7d67a3d9afd844 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 31 Jan 2025 15:48:56 +0800 Subject: [PATCH 01/26] Level-0 --- README.md | 4 ++-- docs/README.md | 2 +- src/main/java/Duke.java | 10 ---------- src/main/java/Thomas.java | 9 +++++++++ text-ui-test/runtest.bat | 2 +- 5 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 src/main/java/Duke.java create mode 100644 src/main/java/Thomas.java diff --git a/README.md b/README.md index af0309a9e..eef852af7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Duke project template +# Thomas project template This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. @@ -13,7 +13,7 @@ Prerequisites: JDK 17, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 17** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -1. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +1. After that, locate the `src/main/java/Thomas.java` file, right-click it, and choose `Run Thomas.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: ``` Hello from ____ _ diff --git a/docs/README.md b/docs/README.md index 47b9f984f..6c90e50c5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Duke User Guide +# Thomas User Guide // Update the title above to match the actual product name diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/Thomas.java b/src/main/java/Thomas.java new file mode 100644 index 000000000..e143b1473 --- /dev/null +++ b/src/main/java/Thomas.java @@ -0,0 +1,9 @@ +public class Thomas { + public static void main(String[] args) { + String greet = "Hello! I'm Thomas\n" + + "What can I do for you?\n" + + "Bye. Hope to see you again soon!"; + + System.out.println(greet); + } +} diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..fbd976f73 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Thomas < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT From 1f4bfd9d9b23ffc7f9ab2a28ebabd552d2c029f2 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Feb 2025 12:51:57 +0800 Subject: [PATCH 02/26] Revert "Level-0" This reverts commit a8435c7934e0ebcddd39ac378c7d67a3d9afd844. --- README.md | 4 ++-- docs/README.md | 2 +- src/main/java/Duke.java | 10 ++++++++++ src/main/java/Thomas.java | 9 --------- text-ui-test/runtest.bat | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 src/main/java/Duke.java delete mode 100644 src/main/java/Thomas.java diff --git a/README.md b/README.md index eef852af7..af0309a9e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Thomas project template +# Duke project template This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. @@ -13,7 +13,7 @@ Prerequisites: JDK 17, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 17** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -1. After that, locate the `src/main/java/Thomas.java` file, right-click it, and choose `Run Thomas.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +1. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: ``` Hello from ____ _ diff --git a/docs/README.md b/docs/README.md index 6c90e50c5..47b9f984f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Thomas User Guide +# Duke User Guide // Update the title above to match the actual product name diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java new file mode 100644 index 000000000..5d313334c --- /dev/null +++ b/src/main/java/Duke.java @@ -0,0 +1,10 @@ +public class Duke { + public static void main(String[] args) { + String logo = " ____ _ \n" + + "| _ \\ _ _| | _____ \n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + } +} diff --git a/src/main/java/Thomas.java b/src/main/java/Thomas.java deleted file mode 100644 index e143b1473..000000000 --- a/src/main/java/Thomas.java +++ /dev/null @@ -1,9 +0,0 @@ -public class Thomas { - public static void main(String[] args) { - String greet = "Hello! I'm Thomas\n" + - "What can I do for you?\n" + - "Bye. Hope to see you again soon!"; - - System.out.println(greet); - } -} diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index fbd976f73..087374464 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Thomas < input.txt > ACTUAL.TXT +java -classpath ..\bin Duke < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT From 0144f1ca77a6639e3be3b794dc82f3bb6060651d Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Feb 2025 12:52:44 +0800 Subject: [PATCH 03/26] Reapply "Level-0" This reverts commit 1f4bfd9d9b23ffc7f9ab2a28ebabd552d2c029f2. --- README.md | 4 ++-- docs/README.md | 2 +- src/main/java/Duke.java | 10 ---------- src/main/java/Thomas.java | 9 +++++++++ text-ui-test/runtest.bat | 2 +- 5 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 src/main/java/Duke.java create mode 100644 src/main/java/Thomas.java diff --git a/README.md b/README.md index af0309a9e..eef852af7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Duke project template +# Thomas project template This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. @@ -13,7 +13,7 @@ Prerequisites: JDK 17, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 17** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -1. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +1. After that, locate the `src/main/java/Thomas.java` file, right-click it, and choose `Run Thomas.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: ``` Hello from ____ _ diff --git a/docs/README.md b/docs/README.md index 47b9f984f..6c90e50c5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Duke User Guide +# Thomas User Guide // Update the title above to match the actual product name diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/Thomas.java b/src/main/java/Thomas.java new file mode 100644 index 000000000..e143b1473 --- /dev/null +++ b/src/main/java/Thomas.java @@ -0,0 +1,9 @@ +public class Thomas { + public static void main(String[] args) { + String greet = "Hello! I'm Thomas\n" + + "What can I do for you?\n" + + "Bye. Hope to see you again soon!"; + + System.out.println(greet); + } +} diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..fbd976f73 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Thomas < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT From e3bd3412a8b8348aa5414ad9325c614b3bc05986 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Feb 2025 13:47:57 +0800 Subject: [PATCH 04/26] Enable ability to echo user's input, exit when it is bye --- src/main/java/Thomas.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/Thomas.java b/src/main/java/Thomas.java index e143b1473..8576a3df2 100644 --- a/src/main/java/Thomas.java +++ b/src/main/java/Thomas.java @@ -1,9 +1,20 @@ +import java.util.Objects; +import java.util.Scanner; + public class Thomas { public static void main(String[] args) { String greet = "Hello! I'm Thomas\n" + - "What can I do for you?\n" + - "Bye. Hope to see you again soon!"; + "What can I do for you?\n"; + String bye = "Bye. Hope to see you again soon!"; + Scanner command = new Scanner(System.in); System.out.println(greet); + String input = command.nextLine(); + while (!Objects.equals(input, "bye")) { + System.out.println(input); + input = command.nextLine(); + } + + System.out.println(bye); } } From 7ce0ae22786b4ba870538a0741c72a22e75838cf Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Feb 2025 21:38:20 +0800 Subject: [PATCH 05/26] Enable the ability to store user's inputs and display them when requested --- README.md | 4 ++-- docs/README.md | 2 +- src/main/java/Elyk.java | 39 +++++++++++++++++++++++++++++++++++++++ src/main/java/Thomas.java | 20 -------------------- text-ui-test/runtest.bat | 2 +- 5 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 src/main/java/Elyk.java delete mode 100644 src/main/java/Thomas.java diff --git a/README.md b/README.md index eef852af7..bc86519ed 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Thomas project template +# Elyk project template This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. @@ -13,7 +13,7 @@ Prerequisites: JDK 17, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 17** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -1. After that, locate the `src/main/java/Thomas.java` file, right-click it, and choose `Run Thomas.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +1. After that, locate the `src/main/java/Elyk.java` file, right-click it, and choose `Run Elyk.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: ``` Hello from ____ _ diff --git a/docs/README.md b/docs/README.md index 6c90e50c5..0d70f1ef2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Thomas User Guide +# Elyk User Guide // Update the title above to match the actual product name diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java new file mode 100644 index 000000000..9883800ff --- /dev/null +++ b/src/main/java/Elyk.java @@ -0,0 +1,39 @@ +import java.util.Scanner; + +public class Elyk { + public static int counter = 0; + public static String[] taskList = new String[100]; + public static Scanner command = new Scanner(System.in); + + public static void main(String[] args) { + String greet = "Hello! I'm Elyk\n" + + "What can I do for you?\n"; + String bye = "Bye. Hope to see you again soon!"; + + System.out.println(greet); + String input = command.nextLine(); + while (!input.equals("bye")) { + if (input.equals("list")) { + printTask(); + } else { + inputTask(input); + } + input = command.nextLine(); + } + + System.out.println(bye); + } + + public static void inputTask(String taskName) { + taskList[counter++] = taskName; + System.out.println("added: " + taskName); + } + + public static void printTask() { + for (int i = 0; i < counter; i++) { + System.out.println((i+1) + ". " + taskList[i]); + } + } +} + + diff --git a/src/main/java/Thomas.java b/src/main/java/Thomas.java deleted file mode 100644 index 8576a3df2..000000000 --- a/src/main/java/Thomas.java +++ /dev/null @@ -1,20 +0,0 @@ -import java.util.Objects; -import java.util.Scanner; - -public class Thomas { - public static void main(String[] args) { - String greet = "Hello! I'm Thomas\n" + - "What can I do for you?\n"; - String bye = "Bye. Hope to see you again soon!"; - - Scanner command = new Scanner(System.in); - System.out.println(greet); - String input = command.nextLine(); - while (!Objects.equals(input, "bye")) { - System.out.println(input); - input = command.nextLine(); - } - - System.out.println(bye); - } -} diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index fbd976f73..e09635375 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Thomas < input.txt > ACTUAL.TXT +java -classpath ..\bin Elyk < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT From 0643a108d8db4e5b544e7bb8261c7aaeac7521f5 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Feb 2025 23:45:04 +0800 Subject: [PATCH 06/26] Add functions to mark and unmark tasks, while adopting a Task class to do so --- src/main/java/Elyk.java | 71 ++++++++++++++++++++++++++++++++--------- src/main/java/Task.java | 21 ++++++++++++ 2 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 9883800ff..11d4e62d0 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -1,37 +1,78 @@ import java.util.Scanner; public class Elyk { - public static int counter = 0; - public static String[] taskList = new String[100]; + public static int taskCounter = 0; + public static int taskNum = 0; + public static String input = ""; + public static Task[] taskList = new Task[100]; public static Scanner command = new Scanner(System.in); public static void main(String[] args) { + greet(); + updateInput(); + + while (true) { + switch (input) { + case "bye": + sayBye(); + System.exit(0); + case "list": + printTask(); + break; + case "mark": + markTaskDone(taskNum); + break; + case "unmark": + markTaskNotDone(taskNum); + break; + default: + inputTask(input); + } + updateInput(); + } + } + + public static void greet() { String greet = "Hello! I'm Elyk\n" + "What can I do for you?\n"; + System.out.println(greet); + } + + public static void sayBye() { String bye = "Bye. Hope to see you again soon!"; + System.out.println(bye); + } - System.out.println(greet); - String input = command.nextLine(); - while (!input.equals("bye")) { - if (input.equals("list")) { - printTask(); - } else { - inputTask(input); - } - input = command.nextLine(); + public static void updateInput() { + input = command.nextLine(); + if (input.matches(".*\\d$")) { + String[] words = input.split(" "); + input = words[0]; + taskNum = Integer.parseInt(words[1]); } + } - System.out.println(bye); + public static void markTaskDone(int taskNum) { + taskList[taskNum - 1].markAsDone(); + System.out.println("Nice! I've marked this task as done:"); + System.out.println(" [X] " + taskList[taskNum - 1].description); + } + + public static void markTaskNotDone(int taskNum) { + taskList[taskNum - 1].markAsNotDone(); + System.out.println("OK, I've marked this task as not done yet:"); + System.out.println(" [ ] " + taskList[taskNum - 1].description); } public static void inputTask(String taskName) { - taskList[counter++] = taskName; + taskList[taskCounter++] = new Task(taskName); System.out.println("added: " + taskName); } public static void printTask() { - for (int i = 0; i < counter; i++) { - System.out.println((i+1) + ". " + taskList[i]); + System.out.println("Here are the tasks in your list:"); + for (int i = 0; i < taskCounter; i++) { + System.out.println((i+1) + ".[" + taskList[i].getStatusIcon() + "] " + taskList[i].description); } } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..2f389e34c --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,21 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + public void markAsDone() { + isDone = true; + } + + public void markAsNotDone() { + isDone = false; + } +} From 9ac48991459abbeb079ec25d5d8d6bad5ff8edac Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Sat, 8 Feb 2025 00:04:44 +0800 Subject: [PATCH 07/26] Optimise the way of getting input and check if the code aligns with coding standard --- src/main/java/Elyk.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 11d4e62d0..429dd55d3 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -9,9 +9,9 @@ public class Elyk { public static void main(String[] args) { greet(); - updateInput(); while (true) { + updateInput(); switch (input) { case "bye": sayBye(); @@ -28,7 +28,6 @@ public static void main(String[] args) { default: inputTask(input); } - updateInput(); } } From dd8334e81182679c2afca56e11e8fafb3f6cc4a3 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Feb 2025 12:28:45 +0800 Subject: [PATCH 08/26] Using inheritance to support tracking 3 types of tasks: Todo, Deadline and Event --- src/main/java/Deadline.java | 14 +++++++++++ src/main/java/Elyk.java | 47 ++++++++++++++++++++++++++++++------- src/main/java/Event.java | 16 +++++++++++++ src/main/java/Task.java | 7 +++++- src/main/java/Todo.java | 11 +++++++++ 5 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..e4e4b232c --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public class Deadline extends Task { + + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (by: " + by + ")"; + } +} diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 429dd55d3..7e3cb7c0b 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -4,6 +4,10 @@ public class Elyk { public static int taskCounter = 0; public static int taskNum = 0; public static String input = ""; + public static String description = ""; + public static String from = ""; + public static String to = ""; + public static String by = ""; public static Task[] taskList = new Task[100]; public static Scanner command = new Scanner(System.in); @@ -25,8 +29,19 @@ public static void main(String[] args) { case "unmark": markTaskNotDone(taskNum); break; + case "todo": + taskList[taskCounter++] = new Todo(description); + inputTask(); + break; + case "deadline": + taskList[taskCounter++] = new Deadline(description, by); + inputTask(); + break; + case "event": + taskList[taskCounter++] = new Event(description, from, to); + inputTask(); + break; default: - inputTask(input); } } } @@ -44,34 +59,50 @@ public static void sayBye() { public static void updateInput() { input = command.nextLine(); - if (input.matches(".*\\d$")) { + if (input.startsWith("mark") || input.startsWith("unmark")) { String[] words = input.split(" "); input = words[0]; taskNum = Integer.parseInt(words[1]); + } else if (input.startsWith("todo")) { + description = input.substring(5); + input = "todo"; + } else if (input.startsWith("deadline")) { + int byPos = input.indexOf("/by"); + by = input.substring(byPos + 4); + description = input.substring(9, byPos - 1); + input = "deadline"; + } else if (input.startsWith("event")) { + int fromPos = input.indexOf("/from"); + int toPos = input.indexOf("/to"); + to = input.substring(toPos + 4); + from = input.substring(fromPos + 6, toPos - 1); + description = input.substring(6, fromPos - 1); + input = "event"; } } public static void markTaskDone(int taskNum) { taskList[taskNum - 1].markAsDone(); System.out.println("Nice! I've marked this task as done:"); - System.out.println(" [X] " + taskList[taskNum - 1].description); + System.out.println(" " + taskList[taskNum - 1]); } public static void markTaskNotDone(int taskNum) { taskList[taskNum - 1].markAsNotDone(); System.out.println("OK, I've marked this task as not done yet:"); - System.out.println(" [ ] " + taskList[taskNum - 1].description); + System.out.println(" " + taskList[taskNum - 1]); } - public static void inputTask(String taskName) { - taskList[taskCounter++] = new Task(taskName); - System.out.println("added: " + taskName); + public static void inputTask() { + System.out.println("Got it. I've added this task:"); + System.out.println(" " + taskList[taskCounter - 1]); + System.out.println("Now you have " + taskCounter + " tasks in the list."); } public static void printTask() { System.out.println("Here are the tasks in your list:"); for (int i = 0; i < taskCounter; i++) { - System.out.println((i+1) + ".[" + taskList[i].getStatusIcon() + "] " + taskList[i].description); + System.out.println((i+1) + "." + taskList[i]); } } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..792644620 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,16 @@ +public class Event extends Task { + + protected String from; + protected String to; + + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; + } +} \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 2f389e34c..dda376955 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -15,7 +15,12 @@ public void markAsDone() { isDone = true; } - public void markAsNotDone() { + public void markAsNotDone() { isDone = false; } + + @Override + public String toString() { + return "[" + getStatusIcon() + "] " + description; + } } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..60b62f05c --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,11 @@ +public class Todo extends Task { + + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} \ No newline at end of file From cb07f89554768b1ad9a0c6e40a238d0a7083e67b Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Feb 2025 13:17:39 +0800 Subject: [PATCH 09/26] Added some exceptions for dealing with errors, like input task type is not supported or there is missing information from the input --- src/main/java/Elyk.java | 11 +++++++++-- src/main/java/ElykException.java | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/main/java/ElykException.java diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 7e3cb7c0b..875608669 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -15,8 +15,9 @@ public static void main(String[] args) { greet(); while (true) { - updateInput(); - switch (input) { + try { + updateInput(); + switch (input) { case "bye": sayBye(); System.exit(0); @@ -42,6 +43,12 @@ public static void main(String[] args) { inputTask(); break; default: + throw new ElykException(); + } + } catch (ElykException e) { + System.out.println(" Sorry :( I currently does not support this command, please try again."); + } catch (IndexOutOfBoundsException e) { + System.out.println(" Hmm... There might be some missing information in your command..."); } } } diff --git a/src/main/java/ElykException.java b/src/main/java/ElykException.java new file mode 100644 index 000000000..7b58dffdc --- /dev/null +++ b/src/main/java/ElykException.java @@ -0,0 +1,3 @@ +public class ElykException extends Exception { + +} From 677104418e24cf6fd7fb899db316a81271b6fb65 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 21 Feb 2025 12:33:04 +0800 Subject: [PATCH 10/26] Using ArrayList instead of an array to store tasks and turned Task into an abstract class --- src/main/java/Elyk.java | 31 ++++++++++++++++++++----------- src/main/java/Task.java | 2 +- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 875608669..b4a6f599e 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; import java.util.Scanner; public class Elyk { @@ -8,7 +9,7 @@ public class Elyk { public static String from = ""; public static String to = ""; public static String by = ""; - public static Task[] taskList = new Task[100]; + public static ArrayList taskList = new ArrayList<>(); public static Scanner command = new Scanner(System.in); public static void main(String[] args) { @@ -29,17 +30,23 @@ public static void main(String[] args) { break; case "unmark": markTaskNotDone(taskNum); + break; + case "delete": + break; case "todo": - taskList[taskCounter++] = new Todo(description); + taskList.add(new Todo(description)); + taskCounter++; inputTask(); break; case "deadline": - taskList[taskCounter++] = new Deadline(description, by); + taskList.add(new Deadline(description, by)); + taskCounter++; inputTask(); break; case "event": - taskList[taskCounter++] = new Event(description, from, to); + taskList.add(new Event(description, from, to)); + taskCounter++; inputTask(); break; default: @@ -66,7 +73,7 @@ public static void sayBye() { public static void updateInput() { input = command.nextLine(); - if (input.startsWith("mark") || input.startsWith("unmark")) { + if (input.startsWith("mark") || input.startsWith("unmark") || input.startsWith("delete")) { String[] words = input.split(" "); input = words[0]; taskNum = Integer.parseInt(words[1]); @@ -89,27 +96,29 @@ public static void updateInput() { } public static void markTaskDone(int taskNum) { - taskList[taskNum - 1].markAsDone(); + taskList.get(taskNum - 1).markAsDone(); System.out.println("Nice! I've marked this task as done:"); - System.out.println(" " + taskList[taskNum - 1]); + System.out.println(" " + taskList.get(taskNum - 1)); } public static void markTaskNotDone(int taskNum) { - taskList[taskNum - 1].markAsNotDone(); + taskList.get(taskNum - 1).markAsNotDone(); System.out.println("OK, I've marked this task as not done yet:"); - System.out.println(" " + taskList[taskNum - 1]); + System.out.println(" " + taskList.get(taskNum - 1)); } public static void inputTask() { System.out.println("Got it. I've added this task:"); - System.out.println(" " + taskList[taskCounter - 1]); + System.out.println(" " + taskList.get(taskCounter - 1)); System.out.println("Now you have " + taskCounter + " tasks in the list."); } + + public static void printTask() { System.out.println("Here are the tasks in your list:"); for (int i = 0; i < taskCounter; i++) { - System.out.println((i+1) + "." + taskList[i]); + System.out.println((i+1) + "." + taskList.get(i)); } } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index dda376955..31b72f928 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,4 +1,4 @@ -public class Task { +public abstract class Task { protected String description; protected boolean isDone; From 1eea51f078c6382c5d137b7d7b74ed1d266c585b Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 21 Feb 2025 12:42:46 +0800 Subject: [PATCH 11/26] Enabled deleting tasks from the list by task index --- src/main/java/Elyk.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index b4a6f599e..c63876131 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -32,21 +32,18 @@ public static void main(String[] args) { markTaskNotDone(taskNum); break; case "delete": - + deleteTask(taskNum); break; case "todo": taskList.add(new Todo(description)); - taskCounter++; inputTask(); break; case "deadline": taskList.add(new Deadline(description, by)); - taskCounter++; inputTask(); break; case "event": taskList.add(new Event(description, from, to)); - taskCounter++; inputTask(); break; default: @@ -108,12 +105,18 @@ public static void markTaskNotDone(int taskNum) { } public static void inputTask() { + taskCounter++; System.out.println("Got it. I've added this task:"); System.out.println(" " + taskList.get(taskCounter - 1)); System.out.println("Now you have " + taskCounter + " tasks in the list."); } - + public static void deleteTask(int taskNum) { + System.out.println("Noted. I've removed this task:"); + System.out.println(" " + taskList.get(taskNum - 1)); + System.out.println("Now you have " + --taskCounter + " tasks in the list."); + taskList.remove(taskList.get(taskNum - 1)); + } public static void printTask() { System.out.println("Here are the tasks in your list:"); From 02b0f40879c77b7f20e72901da7fc43a14093de4 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Mar 2025 05:36:21 +0800 Subject: [PATCH 12/26] Replaced taskCounter with taskList.size() and utilised taskList.getLast() --- src/main/java/Elyk.java | 10 ++++------ src/main/java/META-INF/MANIFEST.MF | 3 +++ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index c63876131..840d17a09 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -2,7 +2,6 @@ import java.util.Scanner; public class Elyk { - public static int taskCounter = 0; public static int taskNum = 0; public static String input = ""; public static String description = ""; @@ -105,22 +104,21 @@ public static void markTaskNotDone(int taskNum) { } public static void inputTask() { - taskCounter++; System.out.println("Got it. I've added this task:"); - System.out.println(" " + taskList.get(taskCounter - 1)); - System.out.println("Now you have " + taskCounter + " tasks in the list."); + System.out.println(" " + taskList.getLast()); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); } public static void deleteTask(int taskNum) { System.out.println("Noted. I've removed this task:"); System.out.println(" " + taskList.get(taskNum - 1)); - System.out.println("Now you have " + --taskCounter + " tasks in the list."); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); taskList.remove(taskList.get(taskNum - 1)); } public static void printTask() { System.out.println("Here are the tasks in your list:"); - for (int i = 0; i < taskCounter; i++) { + for (int i = 0; i < taskList.size(); i++) { System.out.println((i+1) + "." + taskList.get(i)); } } diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..1f3718822 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Elyk + From 4f3ad6c6b8e19a52b1752f7f9a4ead7ee9b635f6 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Mar 2025 07:11:07 +0800 Subject: [PATCH 13/26] Created a new class Storage to deal with loading and saving tasks in a file --- src/main/java/Elyk.java | 2 - src/main/java/Storage.java | 117 +++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 src/main/java/Storage.java diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 875608669..ed5b062ba 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -113,5 +113,3 @@ public static void printTask() { } } } - - diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..8fed545a8 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,117 @@ +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; + +public class Storage { + private static final String DATA_FOLDER = "./data"; + private static final String DATA_FILE = DATA_FOLDER + "/elyk.txt"; + + public static ArrayList loadTasks() { + ArrayList tasks = new ArrayList<>(); + + try { + File directory = new File(DATA_FOLDER); + if (!directory.exists()) { + directory.mkdir(); + } + + File file = new File(DATA_FILE); + if (!file.exists()) { + file.createNewFile(); + return tasks; + } + + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (!line.isEmpty()) { + Task task = parseTaskFromString(line); + if (task != null) { + tasks.add(task); + } + } + } + scanner.close(); + + } catch (IOException e) { + System.out.println("Error loading data: " + e.getMessage()); + } + + return tasks; + } + + public static void saveTasks(ArrayList tasks) { + try { + FileWriter writer = new FileWriter(DATA_FILE); + for (Task task : tasks) { + writer.write(convertTaskToString(task) + "\n"); + } + writer.close(); + + } catch (IOException e) { + System.out.println("Error saving data: " + e.getMessage()); + } + } + + private static String convertTaskToString(Task task) { + StringBuilder sb = new StringBuilder(); + + if (task instanceof Todo) { + sb.append("T"); + } else if (task instanceof Deadline) { + sb.append("D"); + } else if (task instanceof Event) { + sb.append("E"); + } + + sb.append(" | ").append(task.isDone ? "1" : "0"); + sb.append(" | ").append(task.description); + + if (task instanceof Deadline) { + sb.append(" | ").append(((Deadline) task).by); + } else if (task instanceof Event) { + sb.append(" | ").append(((Event) task).from); + sb.append(" | ").append(((Event) task).to); + } + + return sb.toString(); + } + + private static Task parseTaskFromString(String line) { + String[] parts = line.split(" \\| "); + + if (parts.length < 3) { + return null; + } + + String type = parts[0]; + boolean isDone = parts[1].equals("1"); + String description = parts[2]; + + Task task = null; + + switch (type) { + case "T": + task = new Todo(description); + break; + case "D": + if (parts.length > 3) { + task = new Deadline(description, parts[3]); + } + break; + case "E": + if (parts.length > 4) { + task = new Event(description, parts[3], parts[4]); + } + break; + } + + if (task != null && isDone) { + task.markAsDone(); + } + + return task; + } +} From 9be6807c1f4ec0c2cfb6bda7a8159d6dd93e558f Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Mar 2025 07:23:57 +0800 Subject: [PATCH 14/26] Made amendments in parseTaskFromString() so that there is no reassignment of local variable --- src/main/java/Storage.java | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 8fed545a8..f9fc7bf01 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -90,23 +90,12 @@ private static Task parseTaskFromString(String line) { boolean isDone = parts[1].equals("1"); String description = parts[2]; - Task task = null; - - switch (type) { - case "T": - task = new Todo(description); - break; - case "D": - if (parts.length > 3) { - task = new Deadline(description, parts[3]); - } - break; - case "E": - if (parts.length > 4) { - task = new Event(description, parts[3], parts[4]); - } - break; - } + Task task = switch (type) { + case "T" -> new Todo(description); + case "D" -> new Deadline(description, parts[3]); + case "E" -> new Event(description, parts[3], parts[4]); + default -> null; + }; if (task != null && isDone) { task.markAsDone(); From 5d4692dbf3b222b34c758b599fcf07b7d2da8f4c Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Mar 2025 07:46:33 +0800 Subject: [PATCH 15/26] Added loadTasks() and saveTasks() into main() to complete the task saving function --- src/main/java/Elyk.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 7978e1709..3914b19a8 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -12,6 +12,7 @@ public class Elyk { public static Scanner command = new Scanner(System.in); public static void main(String[] args) { + taskList = Storage.loadTasks(); greet(); while (true) { @@ -26,24 +27,30 @@ public static void main(String[] args) { break; case "mark": markTaskDone(taskNum); + Storage.saveTasks(taskList); break; case "unmark": markTaskNotDone(taskNum); + Storage.saveTasks(taskList); break; case "delete": deleteTask(taskNum); + Storage.saveTasks(taskList); break; case "todo": taskList.add(new Todo(description)); inputTask(); + Storage.saveTasks(taskList); break; case "deadline": taskList.add(new Deadline(description, by)); inputTask(); + Storage.saveTasks(taskList); break; case "event": taskList.add(new Event(description, from, to)); inputTask(); + Storage.saveTasks(taskList); break; default: throw new ElykException(); From bd41e9ff60553f2f071f269370d5d569b2432678 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 7 Mar 2025 07:56:17 +0800 Subject: [PATCH 16/26] Fixed the issue of displaying wrong no. of tasks in deleteTask() --- src/main/java/Elyk.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 3914b19a8..e32c5b992 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -119,8 +119,8 @@ public static void inputTask() { public static void deleteTask(int taskNum) { System.out.println("Noted. I've removed this task:"); System.out.println(" " + taskList.get(taskNum - 1)); - System.out.println("Now you have " + taskList.size() + " tasks in the list."); taskList.remove(taskList.get(taskNum - 1)); + System.out.println("Now you have " + taskList.size() + " tasks in the list."); } public static void printTask() { From a8c554cd3d3bce209be460d63927238cc27f7b2c Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 08:29:56 +0800 Subject: [PATCH 17/26] Implemented a new class TaskList to contain the task list in Elyk and created Ui and Parser class Modified code in Elyk and Storage to use TaskList instead --- src/main/java/Elyk.java | 27 +++++++++++++++------------ src/main/java/Parser.java | 2 ++ src/main/java/Storage.java | 15 +++++++-------- src/main/java/TaskList.java | 33 +++++++++++++++++++++++++++++++++ src/main/java/Ui.java | 2 ++ 5 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 src/main/java/Parser.java create mode 100644 src/main/java/TaskList.java create mode 100644 src/main/java/Ui.java diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index e32c5b992..7846e2ba7 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -8,8 +8,11 @@ public class Elyk { public static String from = ""; public static String to = ""; public static String by = ""; - public static ArrayList taskList = new ArrayList<>(); + public static TaskList taskList = new TaskList(); public static Scanner command = new Scanner(System.in); + private Storage storage; + private TaskList tasks; + private Ui ui; public static void main(String[] args) { taskList = Storage.loadTasks(); @@ -38,17 +41,17 @@ public static void main(String[] args) { Storage.saveTasks(taskList); break; case "todo": - taskList.add(new Todo(description)); + taskList.addTask(new Todo(description)); inputTask(); Storage.saveTasks(taskList); break; case "deadline": - taskList.add(new Deadline(description, by)); + taskList.addTask(new Deadline(description, by)); inputTask(); Storage.saveTasks(taskList); break; case "event": - taskList.add(new Event(description, from, to)); + taskList.addTask(new Event(description, from, to)); inputTask(); Storage.saveTasks(taskList); break; @@ -99,34 +102,34 @@ public static void updateInput() { } public static void markTaskDone(int taskNum) { - taskList.get(taskNum - 1).markAsDone(); + taskList.getTask(taskNum - 1).markAsDone(); System.out.println("Nice! I've marked this task as done:"); - System.out.println(" " + taskList.get(taskNum - 1)); + System.out.println(" " + taskList.getTask(taskNum - 1)); } public static void markTaskNotDone(int taskNum) { - taskList.get(taskNum - 1).markAsNotDone(); + taskList.getTask(taskNum - 1).markAsNotDone(); System.out.println("OK, I've marked this task as not done yet:"); - System.out.println(" " + taskList.get(taskNum - 1)); + System.out.println(" " + taskList.getTask(taskNum - 1)); } public static void inputTask() { System.out.println("Got it. I've added this task:"); - System.out.println(" " + taskList.getLast()); + System.out.println(" " + taskList.getTask(taskList.size() - 1)); System.out.println("Now you have " + taskList.size() + " tasks in the list."); } public static void deleteTask(int taskNum) { System.out.println("Noted. I've removed this task:"); - System.out.println(" " + taskList.get(taskNum - 1)); - taskList.remove(taskList.get(taskNum - 1)); + System.out.println(" " + taskList.getTask(taskNum - 1)); + taskList.removeTask(taskNum - 1); System.out.println("Now you have " + taskList.size() + " tasks in the list."); } public static void printTask() { System.out.println("Here are the tasks in your list:"); for (int i = 0; i < taskList.size(); i++) { - System.out.println((i+1) + "." + taskList.get(i)); + System.out.println((i+1) + "." + taskList.getTask(i)); } } } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..4d27fe15e --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,2 @@ +public class Parser { +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index f9fc7bf01..ed5297347 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,15 +1,14 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.util.ArrayList; import java.util.Scanner; public class Storage { private static final String DATA_FOLDER = "./data"; private static final String DATA_FILE = DATA_FOLDER + "/elyk.txt"; - public static ArrayList loadTasks() { - ArrayList tasks = new ArrayList<>(); + public static TaskList loadTasks() { + TaskList tasks = new TaskList(); try { File directory = new File(DATA_FOLDER); @@ -29,29 +28,29 @@ public static ArrayList loadTasks() { if (!line.isEmpty()) { Task task = parseTaskFromString(line); if (task != null) { - tasks.add(task); + tasks.addTask(task); } } } scanner.close(); } catch (IOException e) { - System.out.println("Error loading data: " + e.getMessage()); + System.out.println("There is an error while loading data :(" + e.getMessage()); } return tasks; } - public static void saveTasks(ArrayList tasks) { + public static void saveTasks(TaskList tasks) { try { FileWriter writer = new FileWriter(DATA_FILE); - for (Task task : tasks) { + for (Task task : tasks.getTaskList()) { writer.write(convertTaskToString(task) + "\n"); } writer.close(); } catch (IOException e) { - System.out.println("Error saving data: " + e.getMessage()); + System.out.println("There is an error while saving data :(" + e.getMessage()); } } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..14c978bf0 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; + +public class TaskList { + private ArrayList tasks; + + public TaskList() { + this.tasks = new ArrayList<>(); + } + + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + public void addTask(Task task) { + tasks.add(task); + } + + public void removeTask(int index) { + tasks.remove(index); + } + + public Task getTask(int index) { + return tasks.get(index); + } + + public int size() { + return tasks.size(); + } + + public ArrayList getTaskList() { + return tasks; + } +} \ No newline at end of file diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..30d98a701 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,2 @@ +public class Ui { +} From 934cd37f16932c2e0ce33531cd89e7374a053361 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 09:17:41 +0800 Subject: [PATCH 18/26] Implemented class Ui but yet to incorporate its methods in other classes --- src/main/java/Elyk.java | 1 - src/main/java/Parser.java | 1 + src/main/java/Storage.java | 20 +++++++------- src/main/java/Ui.java | 56 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 7846e2ba7..24301c99f 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -1,4 +1,3 @@ -import java.util.ArrayList; import java.util.Scanner; public class Elyk { diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 4d27fe15e..0019ad645 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,2 +1,3 @@ public class Parser { + } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index ed5297347..785e6a37d 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -55,27 +55,27 @@ public static void saveTasks(TaskList tasks) { } private static String convertTaskToString(Task task) { - StringBuilder sb = new StringBuilder(); + StringBuilder stringBuilder = new StringBuilder(); if (task instanceof Todo) { - sb.append("T"); + stringBuilder.append("T"); } else if (task instanceof Deadline) { - sb.append("D"); + stringBuilder.append("D"); } else if (task instanceof Event) { - sb.append("E"); + stringBuilder.append("E"); } - sb.append(" | ").append(task.isDone ? "1" : "0"); - sb.append(" | ").append(task.description); + stringBuilder.append(" | ").append(task.isDone ? "1" : "0"); + stringBuilder.append(" | ").append(task.description); if (task instanceof Deadline) { - sb.append(" | ").append(((Deadline) task).by); + stringBuilder.append(" | ").append(((Deadline) task).by); } else if (task instanceof Event) { - sb.append(" | ").append(((Event) task).from); - sb.append(" | ").append(((Event) task).to); + stringBuilder.append(" | ").append(((Event) task).from); + stringBuilder.append(" | ").append(((Event) task).to); } - return sb.toString(); + return stringBuilder.toString(); } private static Task parseTaskFromString(String line) { diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 30d98a701..fcf3ad224 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,2 +1,58 @@ +import java.util.Scanner; + public class Ui { + private Scanner scanner; + + public Ui() { + scanner = new Scanner(System.in); + } + + public String getNextCommand() { + return scanner.nextLine(); + } + + public void printErrorMessage(String errorMessage) { + System.out.println(errorMessage); + } + + public static void greet() { + String greet = "Hello! I'm Elyk\n" + + "What can I do for you?\n"; + System.out.println(greet); + } + + public static void sayBye() { + String bye = "Bye. Hope to see you again soon!"; + System.out.println(bye); + } + + public static void markTaskDone(Task task) { + System.out.println("Nice! I've marked this task as done:"); + System.out.println(" " + task); + } + + public static void markTaskNotDone(Task task) { + System.out.println("OK, I've marked this task as not done yet:"); + System.out.println(" " + task); + } + + public static void inputTask(Task task, int taskCounter) { + System.out.println("Got it. I've added this task:"); + System.out.println(" " + task); + System.out.println("Now you have " + taskCounter + " tasks in the list."); + } + + public static void deleteTask(Task task, int taskCounter) { + System.out.println("Noted. I've removed this task:"); + System.out.println(" " + task); + System.out.println("Now you have " + taskCounter + " tasks in the list."); + } + + public static void printTasks() { + System.out.println("Here are the tasks in your list:"); + } + + public static void printIndividualTask(Task task, int i) { + System.out.println((i+1) + "." + task); + } } From 27f12a9636c8bb1cf46f67c2f8d6bc52ee97acd9 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 13:10:12 +0800 Subject: [PATCH 19/26] Completed implementing all new classes for OOP and modified the logic in Elyk to work with them --- src/main/java/Elyk.java | 150 +++++++++++++----------------------- src/main/java/Parser.java | 56 ++++++++++++++ src/main/java/Storage.java | 19 +++-- src/main/java/TaskList.java | 7 +- src/main/java/Ui.java | 16 ++-- 5 files changed, 133 insertions(+), 115 deletions(-) diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 24301c99f..82449d10a 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -1,5 +1,3 @@ -import java.util.Scanner; - public class Elyk { public static int taskNum = 0; public static String input = ""; @@ -7,128 +5,86 @@ public class Elyk { public static String from = ""; public static String to = ""; public static String by = ""; - public static TaskList taskList = new TaskList(); - public static Scanner command = new Scanner(System.in); - private Storage storage; - private TaskList tasks; - private Ui ui; + private static Storage storage; + private static TaskList taskList; + private static Ui ui; + + public Elyk(String elykFile) { + ui = new Ui(); + storage = new Storage(elykFile); + taskList = storage.loadTasks(); + } public static void main(String[] args) { - taskList = Storage.loadTasks(); - greet(); + new Elyk("data/Elyk.txt").run(); + } + + public void run() { + ui.greet(); while (true) { try { - updateInput(); - switch (input) { + input = ui.getNextCommand(); + String commandType = Parser.updateCommand(input); + switch (commandType) { case "bye": - sayBye(); + ui.sayBye(); System.exit(0); case "list": - printTask(); + ui.printTasks(); + for (int i = 0; i < taskList.size(); i++) { + ui.printIndividualTask(taskList.getTask(i), i); + } break; case "mark": - markTaskDone(taskNum); - Storage.saveTasks(taskList); + taskNum = Parser.getTaskNum(input); + Task doneTask = taskList.getTask(taskNum - 1); + doneTask.markAsDone(); + ui.markTaskDone(doneTask); + storage.saveTasks(taskList); break; case "unmark": - markTaskNotDone(taskNum); - Storage.saveTasks(taskList); + taskNum = Parser.getTaskNum(input); + Task notDoneTask = taskList.getTask(taskNum - 1); + notDoneTask.markAsNotDone(); + ui.markTaskNotDone(notDoneTask); + storage.saveTasks(taskList); break; case "delete": - deleteTask(taskNum); - Storage.saveTasks(taskList); + taskNum = Parser.getTaskNum(input); + Task deletedTask = taskList.removeTask(taskNum - 1); + ui.deleteTask(deletedTask, taskList.size()); + storage.saveTasks(taskList); break; case "todo": - taskList.addTask(new Todo(description)); - inputTask(); - Storage.saveTasks(taskList); + description = Parser.getDescription(input, "todo"); + Task addedTodo = taskList.addTask(new Todo(description)); + ui.inputTask(addedTodo, taskList.size()); + storage.saveTasks(taskList); break; case "deadline": - taskList.addTask(new Deadline(description, by)); - inputTask(); - Storage.saveTasks(taskList); + description = Parser.getDescription(input, "deadline"); + by = Parser.getBy(input); + Task addedDeadline = taskList.addTask(new Deadline(description, by)); + ui.inputTask(addedDeadline, taskList.size()); + storage.saveTasks(taskList); break; case "event": - taskList.addTask(new Event(description, from, to)); - inputTask(); - Storage.saveTasks(taskList); + description = Parser.getDescription(input, "event"); + from = Parser.getFrom(input); + to = Parser.getTo(input); + Task addedEvent = taskList.addTask(new Event(description, from, to)); + ui.inputTask(addedEvent, taskList.size()); + storage.saveTasks(taskList); break; default: throw new ElykException(); } } catch (ElykException e) { - System.out.println(" Sorry :( I currently does not support this command, please try again."); + ui.printErrorMessage(" Sorry :( I currently does not support this command, please try again."); } catch (IndexOutOfBoundsException e) { - System.out.println(" Hmm... There might be some missing information in your command..."); + ui.printErrorMessage(" Hmm... There might be some missing information in your command..."); } } } - - public static void greet() { - String greet = "Hello! I'm Elyk\n" + - "What can I do for you?\n"; - System.out.println(greet); - } - - public static void sayBye() { - String bye = "Bye. Hope to see you again soon!"; - System.out.println(bye); - } - - public static void updateInput() { - input = command.nextLine(); - if (input.startsWith("mark") || input.startsWith("unmark") || input.startsWith("delete")) { - String[] words = input.split(" "); - input = words[0]; - taskNum = Integer.parseInt(words[1]); - } else if (input.startsWith("todo")) { - description = input.substring(5); - input = "todo"; - } else if (input.startsWith("deadline")) { - int byPos = input.indexOf("/by"); - by = input.substring(byPos + 4); - description = input.substring(9, byPos - 1); - input = "deadline"; - } else if (input.startsWith("event")) { - int fromPos = input.indexOf("/from"); - int toPos = input.indexOf("/to"); - to = input.substring(toPos + 4); - from = input.substring(fromPos + 6, toPos - 1); - description = input.substring(6, fromPos - 1); - input = "event"; - } - } - - public static void markTaskDone(int taskNum) { - taskList.getTask(taskNum - 1).markAsDone(); - System.out.println("Nice! I've marked this task as done:"); - System.out.println(" " + taskList.getTask(taskNum - 1)); - } - - public static void markTaskNotDone(int taskNum) { - taskList.getTask(taskNum - 1).markAsNotDone(); - System.out.println("OK, I've marked this task as not done yet:"); - System.out.println(" " + taskList.getTask(taskNum - 1)); - } - - public static void inputTask() { - System.out.println("Got it. I've added this task:"); - System.out.println(" " + taskList.getTask(taskList.size() - 1)); - System.out.println("Now you have " + taskList.size() + " tasks in the list."); - } - - public static void deleteTask(int taskNum) { - System.out.println("Noted. I've removed this task:"); - System.out.println(" " + taskList.getTask(taskNum - 1)); - taskList.removeTask(taskNum - 1); - System.out.println("Now you have " + taskList.size() + " tasks in the list."); - } - - public static void printTask() { - System.out.println("Here are the tasks in your list:"); - for (int i = 0; i < taskList.size(); i++) { - System.out.println((i+1) + "." + taskList.getTask(i)); - } - } } diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 0019ad645..511656747 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,3 +1,59 @@ public class Parser { + public static String updateCommand(String input) { + if (input.equals("bye")) { + return "bye"; + } else if (input.equals("list")) { + return "list"; + } else if (input.startsWith("mark")) { + return "mark"; + } else if (input.startsWith("unmark")) { + return "unmark"; + } else if (input.startsWith("delete")) { + return "delete"; + } else if (input.startsWith("todo")) { + return "todo"; + } else if (input.startsWith("deadline")) { + return "deadline"; + } else if (input.startsWith("event")) { + return "event"; + } else { + return "default"; + } + } + public static int getTaskNum(String input) { + String[] words = input.split(" "); + return Integer.parseInt(words[1]); + } + + public static String getDescription(String input, String commandType) { + return switch (commandType) { + case "todo" -> input.substring(5); + case "deadline" -> { + int byPos = input.indexOf("/by"); + yield input.substring(9, byPos - 1); + } + case "event" -> { + int fromPos = input.indexOf("/from"); + yield input.substring(6, fromPos - 1); + } + default -> ""; + }; + } + + public static String getBy(String input) { + int byPos = input.indexOf("/by"); + return input.substring(byPos + 4); + } + + public static String getFrom(String input) { + int fromPos = input.indexOf("/from"); + int toPos = input.indexOf("/to"); + return input.substring(fromPos + 6, toPos - 1); + } + + public static String getTo(String input) { + int toPos = input.indexOf("/to"); + return input.substring(toPos + 4); + } } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 785e6a37d..2b476c6b1 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -4,19 +4,24 @@ import java.util.Scanner; public class Storage { - private static final String DATA_FOLDER = "./data"; - private static final String DATA_FILE = DATA_FOLDER + "/elyk.txt"; + private static String dataFolder; + private static String dataFile; - public static TaskList loadTasks() { + public Storage(String elykFile) { + dataFolder = elykFile.substring(0, elykFile.indexOf("/")); + dataFile = elykFile; + } + + public TaskList loadTasks() { TaskList tasks = new TaskList(); try { - File directory = new File(DATA_FOLDER); + File directory = new File(dataFolder); if (!directory.exists()) { directory.mkdir(); } - File file = new File(DATA_FILE); + File file = new File(dataFile); if (!file.exists()) { file.createNewFile(); return tasks; @@ -41,9 +46,9 @@ public static TaskList loadTasks() { return tasks; } - public static void saveTasks(TaskList tasks) { + public void saveTasks(TaskList tasks) { try { - FileWriter writer = new FileWriter(DATA_FILE); + FileWriter writer = new FileWriter(dataFile); for (Task task : tasks.getTaskList()) { writer.write(convertTaskToString(task) + "\n"); } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 14c978bf0..2e3a23ef7 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -11,12 +11,13 @@ public TaskList(ArrayList tasks) { this.tasks = tasks; } - public void addTask(Task task) { + public Task addTask(Task task) { tasks.add(task); + return task; } - public void removeTask(int index) { - tasks.remove(index); + public Task removeTask(int index) { + return tasks.remove(index); } public Task getTask(int index) { diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index fcf3ad224..93c969e5b 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -15,44 +15,44 @@ public void printErrorMessage(String errorMessage) { System.out.println(errorMessage); } - public static void greet() { + public void greet() { String greet = "Hello! I'm Elyk\n" + "What can I do for you?\n"; System.out.println(greet); } - public static void sayBye() { + public void sayBye() { String bye = "Bye. Hope to see you again soon!"; System.out.println(bye); } - public static void markTaskDone(Task task) { + public void markTaskDone(Task task) { System.out.println("Nice! I've marked this task as done:"); System.out.println(" " + task); } - public static void markTaskNotDone(Task task) { + public void markTaskNotDone(Task task) { System.out.println("OK, I've marked this task as not done yet:"); System.out.println(" " + task); } - public static void inputTask(Task task, int taskCounter) { + public void inputTask(Task task, int taskCounter) { System.out.println("Got it. I've added this task:"); System.out.println(" " + task); System.out.println("Now you have " + taskCounter + " tasks in the list."); } - public static void deleteTask(Task task, int taskCounter) { + public void deleteTask(Task task, int taskCounter) { System.out.println("Noted. I've removed this task:"); System.out.println(" " + task); System.out.println("Now you have " + taskCounter + " tasks in the list."); } - public static void printTasks() { + public void printTasks() { System.out.println("Here are the tasks in your list:"); } - public static void printIndividualTask(Task task, int i) { + public void printIndividualTask(Task task, int i) { System.out.println((i+1) + "." + task); } } From ef12c47e4c8658a201cb811b3299f32e32c8b2a0 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 13:19:28 +0800 Subject: [PATCH 20/26] Added "find" command case and method to extract keyword in Parser class --- src/main/java/Parser.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 511656747..8923a00cf 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -16,6 +16,8 @@ public static String updateCommand(String input) { return "deadline"; } else if (input.startsWith("event")) { return "event"; + } else if (input.startsWith("find")) { + return "find"; } else { return "default"; } @@ -56,4 +58,8 @@ public static String getTo(String input) { int toPos = input.indexOf("/to"); return input.substring(toPos + 4); } + + public static String getKeyword(String input) { + return input.substring(5); + } } From bc5e903c3c7b5836c526b9d202a1f7e3c571fbfd Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 13:38:43 +0800 Subject: [PATCH 21/26] Updated Ui and TaskList classes to find and display matching tasks according to keyword --- src/main/java/Storage.java | 6 +++--- src/main/java/TaskList.java | 10 ++++++++++ src/main/java/Ui.java | 10 ++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 2b476c6b1..8f4400591 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -16,9 +16,9 @@ public TaskList loadTasks() { TaskList tasks = new TaskList(); try { - File directory = new File(dataFolder); - if (!directory.exists()) { - directory.mkdir(); + File folder = new File(dataFolder); + if (!folder.exists()) { + folder.mkdir(); } File file = new File(dataFile); diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 2e3a23ef7..d5e10730d 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -31,4 +31,14 @@ public int size() { public ArrayList getTaskList() { return tasks; } + + public TaskList findMatchingTasks(String keyword) { + TaskList matchingTasks = new TaskList(); + for (Task task : tasks) { + if (task.description.contains(keyword)) { + matchingTasks.addTask(task); + } + } + return matchingTasks; + } } \ No newline at end of file diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 93c969e5b..e2adb9b6d 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -16,8 +16,10 @@ public void printErrorMessage(String errorMessage) { } public void greet() { - String greet = "Hello! I'm Elyk\n" + - "What can I do for you?\n"; + String greet = """ + Hello! I'm Elyk + What can I do for you? + """; System.out.println(greet); } @@ -52,6 +54,10 @@ public void printTasks() { System.out.println("Here are the tasks in your list:"); } + public void printMatchingTasks() { + System.out.println("Here are the matching tasks in your list:"); + } + public void printIndividualTask(Task task, int i) { System.out.println((i+1) + "." + task); } From 21a639fdae341207988cc907d8bc2e89c2029378 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 13:47:51 +0800 Subject: [PATCH 22/26] Updated main logic in Elyk to support finding tasks by a keyword --- src/main/java/Elyk.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 82449d10a..c1c9ddbb6 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -5,6 +5,7 @@ public class Elyk { public static String from = ""; public static String to = ""; public static String by = ""; + public static String keyword = ""; private static Storage storage; private static TaskList taskList; private static Ui ui; @@ -77,6 +78,14 @@ public void run() { ui.inputTask(addedEvent, taskList.size()); storage.saveTasks(taskList); break; + case "find": + keyword = Parser.getKeyword(input); + TaskList foundTasks = taskList.findMatchingTasks(keyword); + ui.printMatchingTasks(); + for (int i = 0; i < foundTasks.size(); i++) { + ui.printIndividualTask(foundTasks.getTask(i), i); + } + break; default: throw new ElykException(); } From 3dc8f6a769b47b969b44fdbb32899af4d69bfb93 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 17:19:06 +0800 Subject: [PATCH 23/26] Added JavaDoc comments to the Ui class and all of its methods --- src/main/java/Ui.java | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 93c969e5b..686d14a97 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,5 +1,9 @@ import java.util.Scanner; +/** + * Deals with all the interactions with the user, mainly getting the input from user and output messages + * corresponding to the command requested by user. + */ public class Ui { private Scanner scanner; @@ -7,51 +11,98 @@ public Ui() { scanner = new Scanner(System.in); } + /** + * Reads the next line of input from user + * + * @return the next command + */ public String getNextCommand() { return scanner.nextLine(); } + /** + * Prints an error message according to a certain error + * + * @param errorMessage the error message intended to be printed + */ public void printErrorMessage(String errorMessage) { System.out.println(errorMessage); } + /** + * Greets the user at the beginning of the program + */ public void greet() { String greet = "Hello! I'm Elyk\n" + "What can I do for you?\n"; System.out.println(greet); } + /** + * Says bye to user before exiting the program + */ public void sayBye() { String bye = "Bye. Hope to see you again soon!"; System.out.println(bye); } + /** + * Prints a message w.r.t. the task being marked done + * + * @param task + */ public void markTaskDone(Task task) { System.out.println("Nice! I've marked this task as done:"); System.out.println(" " + task); } + /** + * Prints a message w.r.t. the task being marked not done + * + * @param task + */ public void markTaskNotDone(Task task) { System.out.println("OK, I've marked this task as not done yet:"); System.out.println(" " + task); } + /** + * Prints a message w.r.t. the task being added and shows the current total no. of tasks + * + * @param task + * @param taskCounter + */ public void inputTask(Task task, int taskCounter) { System.out.println("Got it. I've added this task:"); System.out.println(" " + task); System.out.println("Now you have " + taskCounter + " tasks in the list."); } + /** + * Prints a message w.r.t. the task being deleted and shows the current total no. of tasks + * + * @param task + * @param taskCounter + */ public void deleteTask(Task task, int taskCounter) { System.out.println("Noted. I've removed this task:"); System.out.println(" " + task); System.out.println("Now you have " + taskCounter + " tasks in the list."); } + /** + * Prints a line of message before displaying all the tasks + */ public void printTasks() { System.out.println("Here are the tasks in your list:"); } + /** + * Prints a single task according to its index in the TaskList + * + * @param task + * @param i + */ public void printIndividualTask(Task task, int i) { System.out.println((i+1) + "." + task); } From f5a0f9d092e402e6ff035b363bebc215d35d4e04 Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 21:05:27 +0800 Subject: [PATCH 24/26] Added JavaDoc comments to 3 more classes and all of their non-private methods --- src/main/java/Parser.java | 40 +++++++++++++++++++++++++++++++++++++ src/main/java/Storage.java | 31 ++++++++++++++++++++++++++++ src/main/java/TaskList.java | 38 +++++++++++++++++++++++++++++++---- src/main/java/Ui.java | 16 +++++++-------- 4 files changed, 113 insertions(+), 12 deletions(-) diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 511656747..3a9448f7e 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,4 +1,13 @@ +/** + * Deals with making sense of the user command, i.e. converting it to actions, task no., task description, etc. + */ public class Parser { + /** + * Convert user's input to an action command + * + * @param input line of input from user + * @return command type to be executed + */ public static String updateCommand(String input) { if (input.equals("bye")) { return "bye"; @@ -21,11 +30,24 @@ public static String updateCommand(String input) { } } + /** + * Convert user's input to a specific task no. + * + * @param input line of input from user + * @return task no. of the task user is referring to in the input + */ public static int getTaskNum(String input) { String[] words = input.split(" "); return Integer.parseInt(words[1]); } + /** + * Convert user's input to a specific task description + * + * @param input line of input from user + * @param commandType command type to be executed + * @return description of the task user is referring to in the input + */ public static String getDescription(String input, String commandType) { return switch (commandType) { case "todo" -> input.substring(5); @@ -41,17 +63,35 @@ public static String getDescription(String input, String commandType) { }; } + /** + * Convert user's input to a specific deadline + * + * @param input line of input from user + * @return deadline of the task user is referring to in the input + */ public static String getBy(String input) { int byPos = input.indexOf("/by"); return input.substring(byPos + 4); } + /** + * Convert user's input to a specific start time of an event + * + * @param input line of input from user + * @return start time of the event user is referring to in the input + */ public static String getFrom(String input) { int fromPos = input.indexOf("/from"); int toPos = input.indexOf("/to"); return input.substring(fromPos + 6, toPos - 1); } + /** + * Convert user's input to a specific end time of an event + * + * @param input line of input from user + * @return end time of the event user is referring to in the input + */ public static String getTo(String input) { int toPos = input.indexOf("/to"); return input.substring(toPos + 4); diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 2b476c6b1..dccf9c220 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -3,15 +3,29 @@ import java.io.IOException; import java.util.Scanner; +/** + * Deals with loading tasks from the file and saving tasks in the file, each with + * a helper function to deal with formatting + */ public class Storage { private static String dataFolder; private static String dataFile; + /** + * Constructor of Storage that extracts both the folder and file paths + * + * @param elykFile path of the file used to load and save tasks + */ public Storage(String elykFile) { dataFolder = elykFile.substring(0, elykFile.indexOf("/")); dataFile = elykFile; } + /** + * Loads tasks from the file into a TaskList object + * + * @return a TaskList object containing all tasks loaded from the file + */ public TaskList loadTasks() { TaskList tasks = new TaskList(); @@ -46,6 +60,11 @@ public TaskList loadTasks() { return tasks; } + /** + * Saves tasks into the file from a TaskList object + * + * @param tasks a TaskList object whose tasks are to be saved into the file + */ public void saveTasks(TaskList tasks) { try { FileWriter writer = new FileWriter(dataFile); @@ -59,6 +78,12 @@ public void saveTasks(TaskList tasks) { } } + /** + * Converts a task into a storable String type argument + * + * @param task the task to be saved + * @return a String representing the task + */ private static String convertTaskToString(Task task) { StringBuilder stringBuilder = new StringBuilder(); @@ -83,6 +108,12 @@ private static String convertTaskToString(Task task) { return stringBuilder.toString(); } + /** + * Parses a task from the string stored in the file + * + * @param line a String representing the task to be loaded + * @return a task to be loaded + */ private static Task parseTaskFromString(String line) { String[] parts = line.split(" \\| "); diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 2e3a23ef7..0ba0cfa45 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,33 +1,63 @@ import java.util.ArrayList; +/** + * Contains the task list represented by "tasks" and operations related to it, e.g. to add/delete task in the list + */ public class TaskList { private ArrayList tasks; + /** + * Default constructor of a Task List object + */ public TaskList() { this.tasks = new ArrayList<>(); } - public TaskList(ArrayList tasks) { - this.tasks = tasks; - } - + /** + * Adds a specific task to the task list + * + * @param task task added to the task list + * @return the task added to the task list + */ public Task addTask(Task task) { tasks.add(task); return task; } + /** + * Removes a specific task from the task list + * + * @param index index of the task removed from the task list + * @return the task removed from the task list + */ public Task removeTask(int index) { return tasks.remove(index); } + /** + * Gets a specific task from the task list + * + * @param index index of the task obtained from the taskList + * @return the task obtained from the taskList + */ public Task getTask(int index) { return tasks.get(index); } + /** + * Gets the size of the task list + * + * @return size of the task list + */ public int size() { return tasks.size(); } + /** + * Gets a task list in the form of ArrayList + * + * @return an ArrayList object representing the full task list + */ public ArrayList getTaskList() { return tasks; } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 686d14a97..1a6d77773 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -49,7 +49,7 @@ public void sayBye() { /** * Prints a message w.r.t. the task being marked done * - * @param task + * @param task task being marked done */ public void markTaskDone(Task task) { System.out.println("Nice! I've marked this task as done:"); @@ -59,7 +59,7 @@ public void markTaskDone(Task task) { /** * Prints a message w.r.t. the task being marked not done * - * @param task + * @param task task being marked not done */ public void markTaskNotDone(Task task) { System.out.println("OK, I've marked this task as not done yet:"); @@ -69,8 +69,8 @@ public void markTaskNotDone(Task task) { /** * Prints a message w.r.t. the task being added and shows the current total no. of tasks * - * @param task - * @param taskCounter + * @param task task being added + * @param taskCounter current total no. of tasks */ public void inputTask(Task task, int taskCounter) { System.out.println("Got it. I've added this task:"); @@ -81,8 +81,8 @@ public void inputTask(Task task, int taskCounter) { /** * Prints a message w.r.t. the task being deleted and shows the current total no. of tasks * - * @param task - * @param taskCounter + * @param task task being deleted + * @param taskCounter current total no. of tasks */ public void deleteTask(Task task, int taskCounter) { System.out.println("Noted. I've removed this task:"); @@ -100,8 +100,8 @@ public void printTasks() { /** * Prints a single task according to its index in the TaskList * - * @param task - * @param i + * @param task task i in the TaskList + * @param i index of task */ public void printIndividualTask(Task task, int i) { System.out.println((i+1) + "." + task); From 03f4d46325dfd1fbaa3bc7b16c07617c352dc2da Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 21:34:41 +0800 Subject: [PATCH 25/26] Completed the remaining JavaDoc comments for all classes and methods --- src/main/java/Deadline.java | 14 ++++++++++++++ src/main/java/Elyk.java | 12 ++++++++++++ src/main/java/Event.java | 15 +++++++++++++++ src/main/java/Task.java | 24 ++++++++++++++++++++++++ src/main/java/Todo.java | 14 +++++++++++++- src/main/java/Ui.java | 3 +++ 6 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index e4e4b232c..1593fe5eb 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,12 +1,26 @@ +/** + * A child class of Task class that contains the description and deadline of the tasks + */ public class Deadline extends Task { protected String by; + /** + * Constructor of Deadline class + * + * @param description descriptionof the task + * @param by deadline of the task + */ public Deadline(String description, String by) { super(description); this.by = by; } + /** + * Converts the task to printable String argument + * + * @return a String representing the task + */ @Override public String toString() { return "[D]" + super.toString() + " (by: " + by + ")"; diff --git a/src/main/java/Elyk.java b/src/main/java/Elyk.java index 82449d10a..a89b2149b 100644 --- a/src/main/java/Elyk.java +++ b/src/main/java/Elyk.java @@ -1,3 +1,7 @@ +/** + * The main class of task manager: Elyk, which controls all the executions of the main program by + * utilising the functionality of all the other classes. + */ public class Elyk { public static int taskNum = 0; public static String input = ""; @@ -9,6 +13,11 @@ public class Elyk { private static TaskList taskList; private static Ui ui; + /** + * Constructor of Elyk class which initialises a Storage, TaskList and Ui + * + * @param elykFile path of the file used to load and save tasks + */ public Elyk(String elykFile) { ui = new Ui(); storage = new Storage(elykFile); @@ -19,6 +28,9 @@ public static void main(String[] args) { new Elyk("data/Elyk.txt").run(); } + /** + * Runs all the features that the task manager Elyk contains + */ public void run() { ui.greet(); diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 792644620..da4696a20 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,14 +1,29 @@ +/** + * A child class of Task class that contains the description, start and end time of the tasks + */ public class Event extends Task { protected String from; protected String to; + /** + * Constructor of Event class + * + * @param description description of the task + * @param from start time of the task + * @param to end time of the task + */ public Event(String description, String from, String to) { super(description); this.from = from; this.to = to; } + /** + * Converts the task to printable String argument + * + * @return a String representing the task + */ @Override public String toString() { return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 31b72f928..e7857646b 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,24 +1,48 @@ +/** + * An abstract class that provides a basic template of a Task object + */ public abstract class Task { protected String description; protected boolean isDone; + /** + * Constructor of Task class + * + * @param description description of the task + */ public Task(String description) { this.description = description; this.isDone = false; } + /** + * Convert the task's status of marked/not marked into something printable + * + * @return a symbol that represents whether a task is marked or not + */ public String getStatusIcon() { return (isDone ? "X" : " "); } + /** + * Mark a task as done + */ public void markAsDone() { isDone = true; } + /** + * Mark a task as not done + */ public void markAsNotDone() { isDone = false; } + /** + * Converts the task to printable String argument + * + * @return a String representing the task + */ @Override public String toString() { return "[" + getStatusIcon() + "] " + description; diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 60b62f05c..b2817c3b1 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,9 +1,21 @@ +/** + * A child class of Task class that only contains the description of the tasks + */ public class Todo extends Task { - + /** + * Constructor of Todo class + * + * @param description description of the task + */ public Todo(String description) { super(description); } + /** + * Converts the task to printable String argument + * + * @return a String representing the task + */ @Override public String toString() { return "[T]" + super.toString(); diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 1a6d77773..6fa7c74b3 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -7,6 +7,9 @@ public class Ui { private Scanner scanner; + /** + * Constructor of Ui class that adds a Scanner to receive user's input + */ public Ui() { scanner = new Scanner(System.in); } From 9cc84c029b25d619e77e26492788c0d20b966afb Mon Sep 17 00:00:00 2001 From: Thomas Chiu Date: Fri, 14 Mar 2025 23:17:47 +0800 Subject: [PATCH 26/26] Explained the 9 main features of Elyk in UG --- docs/README.md | 156 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 143 insertions(+), 13 deletions(-) diff --git a/docs/README.md b/docs/README.md index 0d70f1ef2..ea1b8647d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,30 +1,160 @@ # Elyk User Guide -// Update the title above to match the actual product name +Elyk is a Personal Assistant Chatbot that acts as a task manager to +helps users keep track of their tasks via a command line interface (CLI). -// Product screenshot goes here +## Adding ToDos -// Product intro goes here +This feature allows users to add and track tasks that are without any date/time +attached to it, e.g., visit a museum, which are represented by the symbol "T". -## Adding deadlines +Input format: `todo ` -// Describe the action and its outcome. +Example: `todo visit a museum` -// Give examples of usage +Expected output: -Example: `keyword (optional arguments)` +``` +Got it. I've added this task: + [T][ ] visit a museum +Now you have 5 tasks in the list. +``` + +## Adding Deadlines + +This feature allows users to add and track tasks that need to be done before a +specific date/time, e.g., finish proposal by 04/06/2025 9pm, which are represented +by the symbol "D". -// A description of the expected outcome goes here +Input format: `deadline /by ` + +Example: `deadline finish proposal /by 04/06/2025 9pm` + +Expected output: ``` -expected output +Got it. I've added this task: + [D][ ] finish proposal (by: 04/06/2025 9pm) +Now you have 3 tasks in the list. ``` -## Feature ABC +## Adding Events + +This feature allows users to add and track tasks that start at a specific date/time +and ends at a specific date/time, e.g., basketball training 3-6pm, which are represented +by the symbol "E". + +Input format: `event /from /to ` + +Example: `event basketball training /from 3pm /to 6pm` + +Expected output: + +``` +Got it. I've added this task: + [E][ ] basketball training (from: 3pm to: 6pm) +Now you have 7 tasks in the list. +``` + +## Listing tasks + +This feature allows users to view all the tasks that have been stored by Elyk. + +Input format: `list` + +Example: `list` + +Expected output: + +``` +Here are the tasks in your list: +1.[T][X] visit a museum +2.[D][ ] finish proposal (by: 04/06/2025 9pm) +3.[E][ ] basketball training (from: 3pm to: 6pm) +4.[T][X] eat dinner +5.[T][ ] fitness exercises +``` + +## Marking tasks as Done + +This feature allows users to mark tasks as done, which are represented +by the symbol "X". + +Input format: `mark ` + +Example: `mark 3` + +Expected output: + +``` +Nice! I've marked this task as done: + [E][X] basketball training (from: 3pm to: 6pm) +``` -// Feature details +## Marking tasks as Not Done +This feature allows users to mark tasks as done, which are represented +by the symbol " ". -## Feature XYZ +Input format: `unmark ` + +Example: `unmark 1` + +Expected output: + +``` +OK, I've marked this task as not done yet: + [T][ ] visit a museum +``` + +## Deleting tasks + +This feature allows users to delete tasks that have been stored by Elyk. + +Input format: `delete ` + +Example: `delete 2` + +Expected output: + +``` +Noted. I've removed this task: + [D][ ] finish proposal (by: 04/06/2025 9pm) +Now you have 4 tasks in the list. +``` + +## Finding tasks + +This feature allows users to search for tasks that contain a certain keyword +in the description. + +Input format: `find ` + +Example: `find run` + +Expected output: + +``` +Here are the matching tasks in your list: +1.[T][X] run 10k +2.[T][ ] run 5k +3.[T][ ] charity run +4.[D][ ] slow run (by: 5pm) +5.[E][X] running exercise (from: 6pm to: 10pm) +``` + +## Exiting the program + +This feature allows users to say bye to Elyk and exit the chatbot program. + +Input format: `bye` + +Example: `bye` + +Expected output: + +``` +Bye. Hope to see you again soon! -// Feature details \ No newline at end of file +Process finished with exit code 0 +``` \ No newline at end of file