From 48f39ebba4ed0323f920e666bd88c26146b67e83 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 6 Feb 2025 08:18:22 +0800 Subject: [PATCH 01/31] Level-0 --- .gitignore | 3 +++ src/main/java/Bob.java | 12 ++++++++++++ src/main/java/Duke.java | 10 ---------- 3 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 src/main/java/Bob.java delete mode 100644 src/main/java/Duke.java diff --git a/.gitignore b/.gitignore index 2873e189e..846964097 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT + +#Compiled class file +*.class \ No newline at end of file diff --git a/src/main/java/Bob.java b/src/main/java/Bob.java new file mode 100644 index 000000000..b75c8fac6 --- /dev/null +++ b/src/main/java/Bob.java @@ -0,0 +1,12 @@ +public class Bob { + public static void main(String[] args) { + // Prints Initial Greeting + System.out.println("____________________________________________________________"); + System.out.println(" Hello! I'm Bob"); + System.out.println(" What can I do for you?"); + System.out.println("____________________________________________________________"); + System.out.println(" Bye. Hope to see you again soon!"); + System.out.println("____________________________________________________________"); + + } +} 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); - } -} From ab993ab7659b0ba1c325e017144ef9a301dcdf1c Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 6 Feb 2025 08:20:52 +0800 Subject: [PATCH 02/31] Level-1 --- src/main/java/Bob.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/Bob.java b/src/main/java/Bob.java index b75c8fac6..a7a1f5d27 100644 --- a/src/main/java/Bob.java +++ b/src/main/java/Bob.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class Bob { public static void main(String[] args) { // Prints Initial Greeting @@ -5,6 +7,21 @@ public static void main(String[] args) { System.out.println(" Hello! I'm Bob"); System.out.println(" What can I do for you?"); System.out.println("____________________________________________________________"); + + // Scans for input and repeats it back + Scanner scanner = new Scanner(System.in); + String input; + while (true) { + input = scanner.nextLine(); + if (input.equalsIgnoreCase("bye")) { + break; + } + System.out.println("____________________________________________________________"); + System.out.println(input); + System.out.println("____________________________________________________________"); + } + + System.out.println(" Bye. Hope to see you again soon!"); System.out.println("____________________________________________________________"); From 07a7b0cc3e37a90d9252ba27776c0af7831fe2eb Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 6 Feb 2025 08:21:44 +0800 Subject: [PATCH 03/31] Level-1 --- src/main/java/Bob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Bob.java b/src/main/java/Bob.java index a7a1f5d27..2bbbad25f 100644 --- a/src/main/java/Bob.java +++ b/src/main/java/Bob.java @@ -21,7 +21,7 @@ public static void main(String[] args) { System.out.println("____________________________________________________________"); } - + System.out.println("____________________________________________________________"); System.out.println(" Bye. Hope to see you again soon!"); System.out.println("____________________________________________________________"); From f7d1a7662497521916b982f5e874dbaadbcd1b8b Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 6 Feb 2025 09:07:01 +0800 Subject: [PATCH 04/31] Level 2 --- src/main/java/Bob.java | 45 +++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/main/java/Bob.java b/src/main/java/Bob.java index 2bbbad25f..145c520f6 100644 --- a/src/main/java/Bob.java +++ b/src/main/java/Bob.java @@ -2,28 +2,59 @@ public class Bob { public static void main(String[] args) { + + // Prints Initial Greeting System.out.println("____________________________________________________________"); System.out.println(" Hello! I'm Bob"); System.out.println(" What can I do for you?"); System.out.println("____________________________________________________________"); - // Scans for input and repeats it back + // Declare variables Scanner scanner = new Scanner(System.in); String input; + String[] tasks = new String[100]; + int taskCount = 0; + + + // Scans for variables while (true) { input = scanner.nextLine(); if (input.equalsIgnoreCase("bye")) { break; + } + + // "List" command - prints out list + if (input.equalsIgnoreCase("list")) { + System.out.println("____________________________________________________________"); + if (taskCount == 0) { + System.out.println(" No tasks added yet."); + } else { + for (int i = 0; i < taskCount; i++) { + System.out.println((i + 1) + ". " + tasks[i]); + } + } + System.out.println("____________________________________________________________"); + + + } else { + if (taskCount < 100) { + tasks[taskCount++] = input; + System.out.println("____________________________________________________________"); + System.out.println(" added: " + input); + System.out.println("____________________________________________________________"); + } else { + System.out.println("____________________________________________________________"); + System.out.println(" Task list is full!"); + System.out.println("____________________________________________________________"); + } + } + System.out.println("____________________________________________________________"); - System.out.println(input); + System.out.println(" Bye. Hope to see you again soon!"); System.out.println("____________________________________________________________"); - } - - System.out.println("____________________________________________________________"); - System.out.println(" Bye. Hope to see you again soon!"); - System.out.println("____________________________________________________________"); + } } } From 831d116898d728091e2acd13b6aeda78fb246c97 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 6 Feb 2025 09:08:52 +0800 Subject: [PATCH 05/31] Level-2 --- src/main/java/Bob.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/Bob.java b/src/main/java/Bob.java index 145c520f6..1ed33d332 100644 --- a/src/main/java/Bob.java +++ b/src/main/java/Bob.java @@ -51,10 +51,9 @@ public static void main(String[] args) { } } - System.out.println("____________________________________________________________"); - System.out.println(" Bye. Hope to see you again soon!"); - System.out.println("____________________________________________________________"); - } + System.out.println("____________________________________________________________"); + System.out.println(" Bye. Hope to see you again soon!"); + System.out.println("____________________________________________________________"); } } From a1511a82b6103293f9913d87f1cdbf9029e297fe Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 6 Feb 2025 09:20:19 +0800 Subject: [PATCH 06/31] Level-3 --- src/main/java/Bob.java | 59 ----------------------- src/main/java/BobChat.java | 97 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 59 deletions(-) delete mode 100644 src/main/java/Bob.java create mode 100644 src/main/java/BobChat.java diff --git a/src/main/java/Bob.java b/src/main/java/Bob.java deleted file mode 100644 index 1ed33d332..000000000 --- a/src/main/java/Bob.java +++ /dev/null @@ -1,59 +0,0 @@ -import java.util.Scanner; - -public class Bob { - public static void main(String[] args) { - - - // Prints Initial Greeting - System.out.println("____________________________________________________________"); - System.out.println(" Hello! I'm Bob"); - System.out.println(" What can I do for you?"); - System.out.println("____________________________________________________________"); - - // Declare variables - Scanner scanner = new Scanner(System.in); - String input; - String[] tasks = new String[100]; - int taskCount = 0; - - - // Scans for variables - while (true) { - input = scanner.nextLine(); - if (input.equalsIgnoreCase("bye")) { - break; - - } - - // "List" command - prints out list - if (input.equalsIgnoreCase("list")) { - System.out.println("____________________________________________________________"); - if (taskCount == 0) { - System.out.println(" No tasks added yet."); - } else { - for (int i = 0; i < taskCount; i++) { - System.out.println((i + 1) + ". " + tasks[i]); - } - } - System.out.println("____________________________________________________________"); - - - } else { - if (taskCount < 100) { - tasks[taskCount++] = input; - System.out.println("____________________________________________________________"); - System.out.println(" added: " + input); - System.out.println("____________________________________________________________"); - } else { - System.out.println("____________________________________________________________"); - System.out.println(" Task list is full!"); - System.out.println("____________________________________________________________"); - } - } - - } - System.out.println("____________________________________________________________"); - System.out.println(" Bye. Hope to see you again soon!"); - System.out.println("____________________________________________________________"); - } -} diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java new file mode 100644 index 000000000..7c3c4a82c --- /dev/null +++ b/src/main/java/BobChat.java @@ -0,0 +1,97 @@ +import java.util.Scanner; + +class Task { + private final String description; + private boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public void markAsDone() { + isDone = true; + } + + public void markAsNotDone() { + isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "[X] " : "[ ] ") + description; + } +} + +class Bob { + private final Scanner scanner = new Scanner(System.in); + private final String name = "Bob"; + private final Task[] tasks = new Task[100]; + private int taskCount = 0; + + public void start() { + System.out.println("____________________________________________________________"); + System.out.println(" Hello! I'm " + name); + System.out.println(" What can I do for you?"); + System.out.println("____________________________________________________________"); + + String input; + while (true) { + input = scanner.nextLine(); + + if (input.equalsIgnoreCase("bye")) { + break; + } else if (input.equalsIgnoreCase("list")) { + System.out.println("____________________________________________________________"); + System.out.println(" Here are the tasks in your list:"); + if (taskCount == 0) { + System.out.println(" No tasks added yet."); + } else { + for (int i = 0; i < taskCount; i++) { + System.out.println((i + 1) + ". " + tasks[i].getStatusIcon()); + } + } + System.out.println("____________________________________________________________"); + } else if (input.startsWith("mark ")) { + int index = Integer.parseInt(input.substring(5)) - 1; + if (index >= 0 && index < taskCount) { + tasks[index].markAsDone(); + System.out.println("____________________________________________________________"); + System.out.println(" Nice! I've marked this task as done:"); + System.out.println(" " + tasks[index].getStatusIcon()); + System.out.println("____________________________________________________________"); + } + } else if (input.startsWith("unmark ")) { + int index = Integer.parseInt(input.substring(7)) - 1; + if (index >= 0 && index < taskCount) { + tasks[index].markAsNotDone(); + System.out.println("____________________________________________________________"); + System.out.println(" OK, I've marked this task as not done yet:"); + System.out.println(" " + tasks[index].getStatusIcon()); + System.out.println("____________________________________________________________"); + } + } else { + if (taskCount < 100) { + tasks[taskCount++] = new Task(input); + System.out.println("____________________________________________________________"); + System.out.println(" added: " + input); + System.out.println("____________________________________________________________"); + } else { + System.out.println(" Task list is full!"); + } + } + } + + System.out.println("____________________________________________________________"); + System.out.println(" Bye. Hope to see you again soon!"); + System.out.println("____________________________________________________________"); + + scanner.close(); + } +} + +public class BobChat { + public static void main(String[] args) { + Bob chatbot = new Bob(); + chatbot.start(); + } +} From 57d21876a5b146e81a92c238e0ce0c07c868ad6a Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Fri, 7 Feb 2025 12:23:08 +0800 Subject: [PATCH 07/31] Level-4 + code abstraction of Todo, Task, Deadline and Event + Addition of ASCIIArt (BobCHungus) --- src/main/java/ASCII_Art.java | 36 ++++++++++++++++++ src/main/java/BobChat.java | 74 ++++++++++++++++++------------------ src/main/java/Deadline.java | 15 ++++++++ src/main/java/Event.java | 17 +++++++++ src/main/java/Task.java | 27 +++++++++++++ src/main/java/ToDo.java | 12 ++++++ 6 files changed, 144 insertions(+), 37 deletions(-) create mode 100644 src/main/java/ASCII_Art.java create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Task.java create mode 100644 src/main/java/ToDo.java diff --git a/src/main/java/ASCII_Art.java b/src/main/java/ASCII_Art.java new file mode 100644 index 000000000..17aaf01fb --- /dev/null +++ b/src/main/java/ASCII_Art.java @@ -0,0 +1,36 @@ +public class ASCII_Art { + public static String art = """ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣧⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣧⠀⠀⠀⢰⡿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡟⡆⠀⠀⣿⡇⢻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠀⣿⠀⢰⣿⡇⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡄⢸⠀⢸⣿⡇⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡇⢸⡄⠸⣿⡇⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⢸⡅⠀⣿⢠⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣥⣾⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⡿⡿⣿⣿⡿⡅⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠉⠀⠉⡙⢔⠛⣟⢋⠦⢵⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣄⠀⠀⠁⣿⣯⡥⠃⠀⢳⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡇⠀⠀⠀⠐⠠⠊⢀⠀⢸⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⡿⠀⠀⠀⠀⠀⠈⠁⠀⠀⠘⣿⣄⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⣠⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣷⡀⠀⠀⠀ +⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣧⠀⠀ +⠀⠀⠀⡜⣭⠤⢍⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢛⢭⣗⠀ +⠀⠀⠀⠁⠈⠀⠀⣀⠝⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠠⠀⠀⠰⡅ +⠀⠀⠀⢀⠀⠀⡀⠡⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠔⠠⡕⠀ +⠀⠀⠀⠀⣿⣷⣶⠒⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠀⠀⠀⠀ +⠀⠀⠀⠀⠘⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠈⢿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠊⠉⢆⠀⠀⠀⠀ +⠀⢀⠤⠀⠀⢤⣤⣽⣿⣿⣦⣀⢀⡠⢤⡤⠄⠀⠒⠀⠁⠀⠀⠀⢘⠔⠀⠀⠀⠀ +⠀⠀⠀⡐⠈⠁⠈⠛⣛⠿⠟⠑⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠉⠑⠒⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +"""; + + public static void printArt() { + System.out.println(art); + } + +} + + diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index 7c3c4a82c..93bb1e4e9 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -1,43 +1,20 @@ import java.util.Scanner; -class Task { - private final String description; - private boolean isDone; - - public Task(String description) { - this.description = description; - this.isDone = false; - } - - public void markAsDone() { - isDone = true; - } - - public void markAsNotDone() { - isDone = false; - } - - public String getStatusIcon() { - return (isDone ? "[X] " : "[ ] ") + description; - } -} - class Bob { private final Scanner scanner = new Scanner(System.in); - private final String name = "Bob"; private final Task[] tasks = new Task[100]; private int taskCount = 0; public void start() { System.out.println("____________________________________________________________"); - System.out.println(" Hello! I'm " + name); + ASCII_Art.printArt(); + System.out.println(" Hello! I'm BobChungus "); System.out.println(" What can I do for you?"); System.out.println("____________________________________________________________"); - String input; - while (true) { - input = scanner.nextLine(); + while (true) { + String input = scanner.nextLine(); if (input.equalsIgnoreCase("bye")) { break; } else if (input.equalsIgnoreCase("list")) { @@ -47,7 +24,7 @@ public void start() { System.out.println(" No tasks added yet."); } else { for (int i = 0; i < taskCount; i++) { - System.out.println((i + 1) + ". " + tasks[i].getStatusIcon()); + System.out.println((i + 1) + ". " + tasks[i].toString()); } } System.out.println("____________________________________________________________"); @@ -57,7 +34,7 @@ public void start() { tasks[index].markAsDone(); System.out.println("____________________________________________________________"); System.out.println(" Nice! I've marked this task as done:"); - System.out.println(" " + tasks[index].getStatusIcon()); + System.out.println(" " + tasks[index].toString()); System.out.println("____________________________________________________________"); } } else if (input.startsWith("unmark ")) { @@ -66,18 +43,40 @@ public void start() { tasks[index].markAsNotDone(); System.out.println("____________________________________________________________"); System.out.println(" OK, I've marked this task as not done yet:"); - System.out.println(" " + tasks[index].getStatusIcon()); + System.out.println(" " + tasks[index].toString()); System.out.println("____________________________________________________________"); + } else { + System.out.println("Invalid input"); } - } else { - if (taskCount < 100) { - tasks[taskCount++] = new Task(input); - System.out.println("____________________________________________________________"); - System.out.println(" added: " + input); - System.out.println("____________________________________________________________"); + } else if (input.startsWith("todo ")) { + String description = input.substring(5); + tasks[taskCount++] = new ToDo(description); + System.out.println("Now you have " + taskCount + " tasks in the list."); + System.out.println("____________________________________________________________"); + } else if (input.startsWith("deadline ")) { + String[] parts = input.substring(9).split(" /by ", 2); + if (parts.length == 2) { + tasks[taskCount++] = new Deadline(parts[0], parts[1]); + } else { + System.out.println("Invalid deadline description"); + } + System.out.println("Now you have " + taskCount + " tasks in the list."); + System.out.println("____________________________________________________________"); + + } else if (input.startsWith("event ")) { + String[] parts = input.substring(6).split(" /from ", 2); + if (parts.length == 2) { + String[] timeParts = parts[1].split(" /to ", 2); + if (timeParts.length == 2) { + tasks[taskCount++] = new Event(parts[0], timeParts[0], timeParts[1]); + } } else { - System.out.println(" Task list is full!"); + System.out.println("Invalid input, please input a starting and ending time"); } + System.out.println("Now you have " + taskCount + " tasks in the list."); + System.out.println("____________________________________________________________"); + } else { + System.out.println(" Invalid command. Please try again."); } } @@ -87,6 +86,7 @@ public void start() { scanner.close(); } + } public class BobChat { diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..4fd1ca3ff --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,15 @@ + +class Deadline extends Task { + private final String by; + public Deadline(String description, String by) { + super(description); + this.by = by; + System.out.println("I have added this deadline: "); + System.out.println(this); + } + + @Override + public String toString() { + return "[D]" + getStatusIcon() + getDescription() + " (by: " + by + ")"; + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..7f4e3c0af --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,17 @@ +class Event extends Task { + private final String from; + private final String to; + + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + System.out.println("I have added this event: "); + System.out.println(this); + } + + @Override + public String toString() { + return "[E]" + getStatusIcon() + getDescription() + " (from: " + from + " to: " + to + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..972217ac4 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,27 @@ +public class Task { + private final String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public void markAsDone() { + isDone = true; + } + + public void markAsNotDone() { + isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "[X] " : "[ ] "); + } + + public String getDescription() { + return description; + } + +} + diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 000000000..5b9fafb9b --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,12 @@ +public class ToDo extends Task { + public ToDo(String description) { + super(description); + System.out.println("I have added this Todo: "); + System.out.println(this); + } + @Override + public String toString() { + return "[T]" + getStatusIcon() + getDescription(); + } + } + From 6c700143aefb597cb66fc81ce61ceaa1e96d6169 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 13 Feb 2025 09:49:36 +0800 Subject: [PATCH 08/31] added .runtest.bat file for testing --- runtest.bat | 21 +++++++++++++++++++++ src/main/java/ASCII_Art.java | 4 ++++ src/main/java/BobChat.java | 8 ++++++-- src/main/java/Deadline.java | 8 ++++---- src/main/java/Event.java | 12 ++++++------ 5 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 runtest.bat diff --git a/runtest.bat b/runtest.bat new file mode 100644 index 000000000..1a491cd91 --- /dev/null +++ b/runtest.bat @@ -0,0 +1,21 @@ +@ECHO OFF + +REM create bin directory if it doesn't exist +if not exist ..\bin mkdir ..\bin + +REM delete output from previous run +del ACTUAL.TXT + +REM compile the code into the bin folder +javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java +IF ERRORLEVEL 1 ( + echo ********** BUILD FAILURE ********** + exit /b 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 + +REM compare the output to the expected output +FC ACTUAL.TXT EXPECTED.TXT diff --git a/src/main/java/ASCII_Art.java b/src/main/java/ASCII_Art.java index 17aaf01fb..f020ca728 100644 --- a/src/main/java/ASCII_Art.java +++ b/src/main/java/ASCII_Art.java @@ -27,10 +27,14 @@ public class ASCII_Art { ⠀⠀⠉⠑⠒⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ """; + + public static void printArt() { System.out.println(art); } + + } diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index 93bb1e4e9..920f62add 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -17,7 +17,9 @@ public void start() { String input = scanner.nextLine(); if (input.equalsIgnoreCase("bye")) { break; - } else if (input.equalsIgnoreCase("list")) { + } + + if (input.equalsIgnoreCase("list")) { System.out.println("____________________________________________________________"); System.out.println(" Here are the tasks in your list:"); if (taskCount == 0) { @@ -28,7 +30,9 @@ public void start() { } } System.out.println("____________________________________________________________"); - } else if (input.startsWith("mark ")) { + } + + if (input.startsWith("mark ")) { int index = Integer.parseInt(input.substring(5)) - 1; if (index >= 0 && index < taskCount) { tasks[index].markAsDone(); diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 4fd1ca3ff..aca72cd1d 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,15 +1,15 @@ class Deadline extends Task { - private final String by; - public Deadline(String description, String by) { + private final String deadlineBy; + public Deadline(String description, String deadlineBy) { super(description); - this.by = by; + this.deadlineBy = deadlineBy; System.out.println("I have added this deadline: "); System.out.println(this); } @Override public String toString() { - return "[D]" + getStatusIcon() + getDescription() + " (by: " + by + ")"; + return "[D]" + getStatusIcon() + getDescription() + " (by: " + deadlineBy + ")"; } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 7f4e3c0af..1ef9e3569 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,17 +1,17 @@ class Event extends Task { - private final String from; - private final String to; + private final String eventFrom; + private final String eventTo; - public Event(String description, String from, String to) { + public Event(String description, String eventFrom, String eventTo) { super(description); - this.from = from; - this.to = to; + this.eventFrom = eventFrom; + this.eventTo = eventTo; System.out.println("I have added this event: "); System.out.println(this); } @Override public String toString() { - return "[E]" + getStatusIcon() + getDescription() + " (from: " + from + " to: " + to + ")"; + return "[E]" + getStatusIcon() + getDescription() + " (from: " + eventFrom + " to: " + eventTo + ")"; } } From 2cb933b8dd885afc8fa61f1cfaa8c0e0e1c1b493 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 13 Feb 2025 10:49:17 +0800 Subject: [PATCH 09/31] Level-5 --- src/main/java/BobChat.java | 154 ++++++++++++---------- src/main/java/Errors/InputExceptions.java | 31 +++++ 2 files changed, 116 insertions(+), 69 deletions(-) create mode 100644 src/main/java/Errors/InputExceptions.java diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index 920f62add..f68ce7c1e 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -1,11 +1,12 @@ import java.util.Scanner; +import Errors.*; class Bob { private final Scanner scanner = new Scanner(System.in); private final Task[] tasks = new Task[100]; private int taskCount = 0; - public void start() { + public void start() throws InputExceptions { System.out.println("____________________________________________________________"); ASCII_Art.printArt(); System.out.println(" Hello! I'm BobChungus "); @@ -14,87 +15,102 @@ public void start() { while (true) { - String input = scanner.nextLine(); - if (input.equalsIgnoreCase("bye")) { - break; - } + String input = scanner.nextLine().trim(); + String[] inputParts = input.split(" ", 2); + String command = inputParts[0].toLowerCase(); + String arguments = (inputParts.length > 1) ? inputParts[1] : ""; - if (input.equalsIgnoreCase("list")) { - System.out.println("____________________________________________________________"); - System.out.println(" Here are the tasks in your list:"); - if (taskCount == 0) { - System.out.println(" No tasks added yet."); - } else { - for (int i = 0; i < taskCount; i++) { - System.out.println((i + 1) + ". " + tasks[i].toString()); - } - } - System.out.println("____________________________________________________________"); - } + try { + switch (command) { + case "bye": + System.out.println("____________________________________________________________"); + System.out.println(" Bye. Hope to see you again soon!"); + System.out.println("____________________________________________________________"); + scanner.close(); + return; - if (input.startsWith("mark ")) { - int index = Integer.parseInt(input.substring(5)) - 1; - if (index >= 0 && index < taskCount) { - tasks[index].markAsDone(); - System.out.println("____________________________________________________________"); - System.out.println(" Nice! I've marked this task as done:"); - System.out.println(" " + tasks[index].toString()); - System.out.println("____________________________________________________________"); - } - } else if (input.startsWith("unmark ")) { - int index = Integer.parseInt(input.substring(7)) - 1; - if (index >= 0 && index < taskCount) { - tasks[index].markAsNotDone(); - System.out.println("____________________________________________________________"); - System.out.println(" OK, I've marked this task as not done yet:"); - System.out.println(" " + tasks[index].toString()); - System.out.println("____________________________________________________________"); - } else { - System.out.println("Invalid input"); - } - } else if (input.startsWith("todo ")) { - String description = input.substring(5); - tasks[taskCount++] = new ToDo(description); - System.out.println("Now you have " + taskCount + " tasks in the list."); - System.out.println("____________________________________________________________"); - } else if (input.startsWith("deadline ")) { - String[] parts = input.substring(9).split(" /by ", 2); - if (parts.length == 2) { - tasks[taskCount++] = new Deadline(parts[0], parts[1]); - } else { - System.out.println("Invalid deadline description"); + case "list": + System.out.println("____________________________________________________________"); + System.out.println(" Here are the tasks in your list:"); + if (taskCount == 0) { + System.out.println("No tasks added yet."); + } else { + for (int i = 0; i < taskCount; i++) { + System.out.println((i + 1) + ". " + tasks[i].toString()); + } + } + System.out.println("____________________________________________________________"); + break; + + case "mark": + if (arguments.isEmpty()) throw new InputExceptions.MissingArgumentException("mark"); + int markIndex = Integer.parseInt(arguments) - 1; + if (markIndex < 0 || markIndex >= taskCount) throw new InputExceptions("mark target must exist"); + tasks[markIndex].markAsDone(); + System.out.println("____________________________________________________________"); + System.out.println(" Nice! I've marked this task as done:"); + System.out.println(" " + tasks[markIndex].toString()); + System.out.println("____________________________________________________________"); + break; + + case "unmark": + if (arguments.isEmpty()) throw new InputExceptions("unmark failed, no arguments"); + int unmarkIndex = Integer.parseInt(arguments) - 1; + if (unmarkIndex < 0 || unmarkIndex >= taskCount) + throw new InputExceptions.InvalidIndexException(); + tasks[unmarkIndex].markAsNotDone(); + System.out.println("____________________________________________________________"); + System.out.println(" OK, I've marked this task as not done yet:"); + System.out.println(" " + tasks[unmarkIndex].toString()); + System.out.println("____________________________________________________________"); + break; + + case "todo": + if (arguments.isEmpty()) { + throw new InputExceptions.MissingArgumentException("todo"); + } + tasks[taskCount++] = new ToDo(arguments); + System.out.println("Now you have " + taskCount + " tasks in the list."); + System.out.println("____________________________________________________________"); + break; + + case "deadline": + String[] parts = arguments.split(" /by ", 2); + if (parts.length < 2) throw new InputExceptions.MissingArgumentException("deadline"); + tasks[taskCount++] = new Deadline(parts[0], parts[1]); + System.out.println("Now you have " + taskCount + " tasks in the list."); + System.out.println("____________________________________________________________"); + break; + + case "event": + String[] eventParts = arguments.split(" /from ", 2); + if (eventParts.length < 2) throw new InputExceptions.MissingArgumentException("event"); + String[] timeParts = eventParts[1].split(" /to ", 2); + if (timeParts.length < 2) throw new InputExceptions.MissingArgumentException("event timing"); + tasks[taskCount++] = new Event(eventParts[0], timeParts[0], timeParts[1]); + System.out.println("Now you have " + taskCount + " tasks in the list."); + System.out.println("____________________________________________________________"); + break; + + default: + throw new InputExceptions.InvalidCommandException(); } - System.out.println("Now you have " + taskCount + " tasks in the list."); + + } catch (InputExceptions e) { + System.out.println("Error: " + e.getMessage()); System.out.println("____________________________________________________________"); - } else if (input.startsWith("event ")) { - String[] parts = input.substring(6).split(" /from ", 2); - if (parts.length == 2) { - String[] timeParts = parts[1].split(" /to ", 2); - if (timeParts.length == 2) { - tasks[taskCount++] = new Event(parts[0], timeParts[0], timeParts[1]); - } - } else { - System.out.println("Invalid input, please input a starting and ending time"); - } - System.out.println("Now you have " + taskCount + " tasks in the list."); + } catch (NumberFormatException e) { + System.out.println("Error: Please enter a valid number."); System.out.println("____________________________________________________________"); - } else { - System.out.println(" Invalid command. Please try again."); } } - - System.out.println("____________________________________________________________"); - System.out.println(" Bye. Hope to see you again soon!"); - System.out.println("____________________________________________________________"); - - scanner.close(); } } public class BobChat { - public static void main(String[] args) { + public static void main(String[] args) throws InputExceptions { Bob chatbot = new Bob(); chatbot.start(); } diff --git a/src/main/java/Errors/InputExceptions.java b/src/main/java/Errors/InputExceptions.java new file mode 100644 index 000000000..05f5d044e --- /dev/null +++ b/src/main/java/Errors/InputExceptions.java @@ -0,0 +1,31 @@ +package Errors; + +public class InputExceptions extends Exception { + public InputExceptions(String message) { + super(message); + } + + public static class MissingArgumentException extends InputExceptions { + public MissingArgumentException(String command) { + super(command + " must have arguments."); + } + } + + public static class InvalidIndexException extends InputExceptions { + public InvalidIndexException() { + super("Invalid task number."); + } + } + + public static class InvalidCommandException extends InputExceptions { + public InvalidCommandException() { + super("Invalid command. Please try again."); + } + } + + public static class NumberFormatException extends InputExceptions { + public NumberFormatException() { + super("Error: Please enter a valid number."); + } + } +} \ No newline at end of file From b55d25cccf7416b7a382e6232315db0c3535d8fd Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Fri, 21 Feb 2025 21:14:14 +0800 Subject: [PATCH 10/31] added ArrayList and Level-5 --- src/main/java/BobChat.java | 52 +++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index f68ce7c1e..c1fcef207 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -1,10 +1,10 @@ +import java.util.ArrayList; import java.util.Scanner; import Errors.*; class Bob { private final Scanner scanner = new Scanner(System.in); - private final Task[] tasks = new Task[100]; - private int taskCount = 0; + private final ArrayList tasks = new ArrayList<>(); public void start() throws InputExceptions { System.out.println("____________________________________________________________"); @@ -32,11 +32,11 @@ public void start() throws InputExceptions { case "list": System.out.println("____________________________________________________________"); System.out.println(" Here are the tasks in your list:"); - if (taskCount == 0) { + if (tasks.isEmpty()) { System.out.println("No tasks added yet."); } else { - for (int i = 0; i < taskCount; i++) { - System.out.println((i + 1) + ". " + tasks[i].toString()); + for (int i = 0; i < tasks.size(); i++) { + System.out.println((i + 1) + ". " + tasks.get(i).toString()); } } System.out.println("____________________________________________________________"); @@ -45,23 +45,23 @@ public void start() throws InputExceptions { case "mark": if (arguments.isEmpty()) throw new InputExceptions.MissingArgumentException("mark"); int markIndex = Integer.parseInt(arguments) - 1; - if (markIndex < 0 || markIndex >= taskCount) throw new InputExceptions("mark target must exist"); - tasks[markIndex].markAsDone(); + if (markIndex < 0 || markIndex > tasks.size()) throw new InputExceptions("mark target must exist"); + tasks.get(markIndex).markAsDone(); System.out.println("____________________________________________________________"); System.out.println(" Nice! I've marked this task as done:"); - System.out.println(" " + tasks[markIndex].toString()); + System.out.println(" " + tasks.get(markIndex).toString()); System.out.println("____________________________________________________________"); break; case "unmark": if (arguments.isEmpty()) throw new InputExceptions("unmark failed, no arguments"); int unmarkIndex = Integer.parseInt(arguments) - 1; - if (unmarkIndex < 0 || unmarkIndex >= taskCount) + if (unmarkIndex < 0 || unmarkIndex > tasks.size()) throw new InputExceptions.InvalidIndexException(); - tasks[unmarkIndex].markAsNotDone(); + tasks.get(unmarkIndex).markAsNotDone(); System.out.println("____________________________________________________________"); System.out.println(" OK, I've marked this task as not done yet:"); - System.out.println(" " + tasks[unmarkIndex].toString()); + System.out.println(" " + tasks.get(unmarkIndex).toString()); System.out.println("____________________________________________________________"); break; @@ -69,16 +69,16 @@ public void start() throws InputExceptions { if (arguments.isEmpty()) { throw new InputExceptions.MissingArgumentException("todo"); } - tasks[taskCount++] = new ToDo(arguments); - System.out.println("Now you have " + taskCount + " tasks in the list."); + tasks.add( new ToDo(arguments) ); + System.out.println("Now you have " + (tasks.size() + 1) + " tasks in the list."); System.out.println("____________________________________________________________"); break; case "deadline": String[] parts = arguments.split(" /by ", 2); if (parts.length < 2) throw new InputExceptions.MissingArgumentException("deadline"); - tasks[taskCount++] = new Deadline(parts[0], parts[1]); - System.out.println("Now you have " + taskCount + " tasks in the list."); + tasks.add( new Deadline(parts[0], parts[1])); + System.out.println("Now you have " + (tasks.size() + 1) + " tasks in the list."); System.out.println("____________________________________________________________"); break; @@ -87,11 +87,29 @@ public void start() throws InputExceptions { if (eventParts.length < 2) throw new InputExceptions.MissingArgumentException("event"); String[] timeParts = eventParts[1].split(" /to ", 2); if (timeParts.length < 2) throw new InputExceptions.MissingArgumentException("event timing"); - tasks[taskCount++] = new Event(eventParts[0], timeParts[0], timeParts[1]); - System.out.println("Now you have " + taskCount + " tasks in the list."); + tasks.add( new Event(eventParts[0], timeParts[0], timeParts[1])); + System.out.println("Now you have " + (tasks.size() + 1) + " tasks in the list."); System.out.println("____________________________________________________________"); break; + case "delete": + if (arguments.isEmpty()) { + throw new InputExceptions.MissingArgumentException("todo"); + } + int deleteIndex = Integer.parseInt(arguments) - 1; + if (deleteIndex < 0 || deleteIndex > tasks.size()) { + throw new InputExceptions.InvalidIndexException(); + } + Task removedTask = tasks.remove(deleteIndex); + System.out.println("____________________________________________________________"); + System.out.println(" Noted. I've removed this task:"); + System.out.println(" " + removedTask); + System.out.println("Now you have " + tasks.size() + 1 + " tasks in the list."); + System.out.println("____________________________________________________________"); + break; + + + default: throw new InputExceptions.InvalidCommandException(); } From a19da34d04c575b323dfffa5109c32554e5ac59c Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Sat, 22 Feb 2025 02:31:30 +0800 Subject: [PATCH 11/31] Level-7 --- data/userTasks.txt | 0 src/main/java/BobChat.java | 59 ++++++++++++++++++++++++++---- src/main/java/META-INF/MANIFEST.MF | 3 ++ src/main/java/Task.java | 5 +++ 4 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 data/userTasks.txt create mode 100644 src/main/java/META-INF/MANIFEST.MF diff --git a/data/userTasks.txt b/data/userTasks.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index c1fcef207..95c8d08cb 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -1,10 +1,47 @@ +import java.io.*; import java.util.ArrayList; import java.util.Scanner; import Errors.*; + class Bob { private final Scanner scanner = new Scanner(System.in); - private final ArrayList tasks = new ArrayList<>(); + + private final String filepath = "data/userTasks.txt"; + private static final ArrayList tasks = new ArrayList<>(); + + // Load tasks from file + private static void loadFileContents(String filePath) throws FileNotFoundException { + File file = new File(filePath); + if (!file.exists()) { + System.out.println("File does not exist, starting with an empty list."); + return; + } + + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + tasks.add(Task.fromString(line)); // Convert line to Task and add + } + scanner.close(); + System.out.println("Tasks loaded successfully."); + } + + // Save tasks to file + private static void saveFileContents(String filePath) { + try (FileWriter fileWriter = new FileWriter(filePath); + PrintWriter writer = new PrintWriter(fileWriter)) { + + for (Task task : tasks) { + writer.println(task); // Uses Task's toString() method + } + + System.out.println("Tasks saved successfully."); + } catch (IOException e) { + System.err.println("Error saving tasks: " + e.getMessage()); + } + } + public void start() throws InputExceptions { System.out.println("____________________________________________________________"); @@ -13,6 +50,11 @@ public void start() throws InputExceptions { System.out.println(" What can I do for you?"); System.out.println("____________________________________________________________"); + try { + loadFileContents(filepath); // Call method inside try block + } catch (FileNotFoundException e) { + System.err.println("Error: File not found. " + e.getMessage()); + } while (true) { String input = scanner.nextLine().trim(); @@ -26,6 +68,7 @@ public void start() throws InputExceptions { System.out.println("____________________________________________________________"); System.out.println(" Bye. Hope to see you again soon!"); System.out.println("____________________________________________________________"); + saveFileContents(filepath); scanner.close(); return; @@ -45,7 +88,7 @@ public void start() throws InputExceptions { case "mark": if (arguments.isEmpty()) throw new InputExceptions.MissingArgumentException("mark"); int markIndex = Integer.parseInt(arguments) - 1; - if (markIndex < 0 || markIndex > tasks.size()) throw new InputExceptions("mark target must exist"); + if (markIndex < 0 || markIndex >= tasks.size()) throw new InputExceptions("mark target must exist"); tasks.get(markIndex).markAsDone(); System.out.println("____________________________________________________________"); System.out.println(" Nice! I've marked this task as done:"); @@ -56,7 +99,7 @@ public void start() throws InputExceptions { case "unmark": if (arguments.isEmpty()) throw new InputExceptions("unmark failed, no arguments"); int unmarkIndex = Integer.parseInt(arguments) - 1; - if (unmarkIndex < 0 || unmarkIndex > tasks.size()) + if (unmarkIndex < 0 || unmarkIndex >= tasks.size()) throw new InputExceptions.InvalidIndexException(); tasks.get(unmarkIndex).markAsNotDone(); System.out.println("____________________________________________________________"); @@ -70,7 +113,7 @@ public void start() throws InputExceptions { throw new InputExceptions.MissingArgumentException("todo"); } tasks.add( new ToDo(arguments) ); - System.out.println("Now you have " + (tasks.size() + 1) + " tasks in the list."); + System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); System.out.println("____________________________________________________________"); break; @@ -78,7 +121,7 @@ public void start() throws InputExceptions { String[] parts = arguments.split(" /by ", 2); if (parts.length < 2) throw new InputExceptions.MissingArgumentException("deadline"); tasks.add( new Deadline(parts[0], parts[1])); - System.out.println("Now you have " + (tasks.size() + 1) + " tasks in the list."); + System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); System.out.println("____________________________________________________________"); break; @@ -88,7 +131,7 @@ public void start() throws InputExceptions { String[] timeParts = eventParts[1].split(" /to ", 2); if (timeParts.length < 2) throw new InputExceptions.MissingArgumentException("event timing"); tasks.add( new Event(eventParts[0], timeParts[0], timeParts[1])); - System.out.println("Now you have " + (tasks.size() + 1) + " tasks in the list."); + System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); System.out.println("____________________________________________________________"); break; @@ -97,14 +140,14 @@ public void start() throws InputExceptions { throw new InputExceptions.MissingArgumentException("todo"); } int deleteIndex = Integer.parseInt(arguments) - 1; - if (deleteIndex < 0 || deleteIndex > tasks.size()) { + if (deleteIndex < 0 || deleteIndex >= tasks.size()) { throw new InputExceptions.InvalidIndexException(); } Task removedTask = tasks.remove(deleteIndex); System.out.println("____________________________________________________________"); System.out.println(" Noted. I've removed this task:"); System.out.println(" " + removedTask); - System.out.println("Now you have " + tasks.size() + 1 + " tasks in the list."); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); System.out.println("____________________________________________________________"); break; diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..a630d3fc2 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: BobChat + diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 972217ac4..362c410de 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -7,6 +7,11 @@ public Task(String description) { this.isDone = false; } + public static Task fromString(String line) { + String[] parts = line.split("\n"); + return new Task(parts[0]); + } + public void markAsDone() { isDone = true; } From 17f8b698f0838041ceaa49164929d5eda330bf73 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 5 Mar 2025 20:36:35 +0800 Subject: [PATCH 12/31] removed user data from git push --- .gitignore | 5 ++++- data/userTasks.txt | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 846964097..405640353 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,7 @@ bin/ text-ui-test/EXPECTED-UNIX.TXT #Compiled class file -*.class \ No newline at end of file +*.class + +# userdata +/data/ diff --git a/data/userTasks.txt b/data/userTasks.txt index e69de29bb..34f95f2dc 100644 --- a/data/userTasks.txt +++ b/data/userTasks.txt @@ -0,0 +1 @@ +[T][ ] 1234 From f7e39c35babcf547ea9a4c1a5ced5c12f1c1806e Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 5 Mar 2025 20:48:48 +0800 Subject: [PATCH 13/31] added classes - not implemented yet --- src/main/java/Parser.java | 2 ++ src/main/java/Storage.java | 19 +++++++++++++++++++ src/main/java/TaskList.java | 2 ++ src/main/java/Ui.java | 5 +++++ 4 files changed, 28 insertions(+) create mode 100644 src/main/java/Parser.java create mode 100644 src/main/java/Storage.java create mode 100644 src/main/java/TaskList.java create mode 100644 src/main/java/Ui.java 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 new file mode 100644 index 000000000..56b3e6412 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,19 @@ +public class Storage { + private static String filePath = "data/userTasks.txt"; + + + public void saveData(String data) { + // Implement file writing logic here + + } + + public String loadData() { + // Implement file reading logic here + + return ""; // Return loaded data + } + +} + + + diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..1e7aed1c0 --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,2 @@ +public class TaskList { +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..667400c3f --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,5 @@ +public class Ui { + + + +} From 0a8bc50e4e6b6d269df9b18abfc28217844bbd4f Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Sat, 8 Mar 2025 16:12:01 +0800 Subject: [PATCH 14/31] 7.1 --- data/userTasks.txt | 2 +- src/main/java/BobChat.java | 327 ++++++++++++---------- src/main/java/Deadline.java | 4 + src/main/java/Errors/InputExceptions.java | 29 +- src/main/java/Event.java | 8 + src/main/java/Parser.java | 63 ++++- src/main/java/Storage.java | 94 ++++++- src/main/java/TaskList.java | 34 ++- src/main/java/Ui.java | 34 ++- 9 files changed, 425 insertions(+), 170 deletions(-) diff --git a/data/userTasks.txt b/data/userTasks.txt index 34f95f2dc..d8e8e105a 100644 --- a/data/userTasks.txt +++ b/data/userTasks.txt @@ -1 +1 @@ -[T][ ] 1234 +todo|do homework diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index 95c8d08cb..3f013a7d9 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -1,178 +1,207 @@ import java.io.*; -import java.util.ArrayList; -import java.util.Scanner; +//import java.util.ArrayList; +//import java.util.Scanner; import Errors.*; class Bob { - private final Scanner scanner = new Scanner(System.in); - private final String filepath = "data/userTasks.txt"; - private static final ArrayList tasks = new ArrayList<>(); - - // Load tasks from file - private static void loadFileContents(String filePath) throws FileNotFoundException { - File file = new File(filePath); - if (!file.exists()) { - System.out.println("File does not exist, starting with an empty list."); - return; - } - - Scanner scanner = new Scanner(file); - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); - tasks.add(Task.fromString(line)); // Convert line to Task and add - } - scanner.close(); - System.out.println("Tasks loaded successfully."); + Bob() throws FileNotFoundException { } - // Save tasks to file - private static void saveFileContents(String filePath) { - try (FileWriter fileWriter = new FileWriter(filePath); - PrintWriter writer = new PrintWriter(fileWriter)) { +// private final Scanner scanner = new Scanner(System.in); + private final UI ui = new UI(); + private final Storage storage = new Storage("data/userTasks.txt"); + private final TaskList taskList = new TaskList( storage.loadTasks()); - for (Task task : tasks) { - writer.println(task); // Uses Task's toString() method - } - System.out.println("Tasks saved successfully."); - } catch (IOException e) { - System.err.println("Error saving tasks: " + e.getMessage()); - } - } +// private final String filepath = "data/userTasks.txt"; +// static final ArrayList tasks = new ArrayList<>(); public void start() throws InputExceptions { - System.out.println("____________________________________________________________"); - ASCII_Art.printArt(); - System.out.println(" Hello! I'm BobChungus "); - System.out.println(" What can I do for you?"); - System.out.println("____________________________________________________________"); - - try { - loadFileContents(filepath); // Call method inside try block - } catch (FileNotFoundException e) { - System.err.println("Error: File not found. " + e.getMessage()); - } - + ui.showWelcome(); while (true) { - String input = scanner.nextLine().trim(); - String[] inputParts = input.split(" ", 2); - String command = inputParts[0].toLowerCase(); - String arguments = (inputParts.length > 1) ? inputParts[1] : ""; - + String userInput = ui.getUserInput(); +// Parser.parseCommand(userInput, taskList, storage, ui); try { - switch (command) { - case "bye": - System.out.println("____________________________________________________________"); - System.out.println(" Bye. Hope to see you again soon!"); - System.out.println("____________________________________________________________"); - saveFileContents(filepath); - scanner.close(); - return; - - case "list": - System.out.println("____________________________________________________________"); - System.out.println(" Here are the tasks in your list:"); - if (tasks.isEmpty()) { - System.out.println("No tasks added yet."); - } else { - for (int i = 0; i < tasks.size(); i++) { - System.out.println((i + 1) + ". " + tasks.get(i).toString()); - } - } - System.out.println("____________________________________________________________"); - break; - - case "mark": - if (arguments.isEmpty()) throw new InputExceptions.MissingArgumentException("mark"); - int markIndex = Integer.parseInt(arguments) - 1; - if (markIndex < 0 || markIndex >= tasks.size()) throw new InputExceptions("mark target must exist"); - tasks.get(markIndex).markAsDone(); - System.out.println("____________________________________________________________"); - System.out.println(" Nice! I've marked this task as done:"); - System.out.println(" " + tasks.get(markIndex).toString()); - System.out.println("____________________________________________________________"); - break; - - case "unmark": - if (arguments.isEmpty()) throw new InputExceptions("unmark failed, no arguments"); - int unmarkIndex = Integer.parseInt(arguments) - 1; - if (unmarkIndex < 0 || unmarkIndex >= tasks.size()) - throw new InputExceptions.InvalidIndexException(); - tasks.get(unmarkIndex).markAsNotDone(); - System.out.println("____________________________________________________________"); - System.out.println(" OK, I've marked this task as not done yet:"); - System.out.println(" " + tasks.get(unmarkIndex).toString()); - System.out.println("____________________________________________________________"); - break; - - case "todo": - if (arguments.isEmpty()) { - throw new InputExceptions.MissingArgumentException("todo"); - } - tasks.add( new ToDo(arguments) ); - System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); - System.out.println("____________________________________________________________"); - break; - - case "deadline": - String[] parts = arguments.split(" /by ", 2); - if (parts.length < 2) throw new InputExceptions.MissingArgumentException("deadline"); - tasks.add( new Deadline(parts[0], parts[1])); - System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); - System.out.println("____________________________________________________________"); - break; - - case "event": - String[] eventParts = arguments.split(" /from ", 2); - if (eventParts.length < 2) throw new InputExceptions.MissingArgumentException("event"); - String[] timeParts = eventParts[1].split(" /to ", 2); - if (timeParts.length < 2) throw new InputExceptions.MissingArgumentException("event timing"); - tasks.add( new Event(eventParts[0], timeParts[0], timeParts[1])); - System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); - System.out.println("____________________________________________________________"); - break; - - case "delete": - if (arguments.isEmpty()) { - throw new InputExceptions.MissingArgumentException("todo"); - } - int deleteIndex = Integer.parseInt(arguments) - 1; - if (deleteIndex < 0 || deleteIndex >= tasks.size()) { - throw new InputExceptions.InvalidIndexException(); - } - Task removedTask = tasks.remove(deleteIndex); - System.out.println("____________________________________________________________"); - System.out.println(" Noted. I've removed this task:"); - System.out.println(" " + removedTask); - System.out.println("Now you have " + tasks.size() + " tasks in the list."); - System.out.println("____________________________________________________________"); - break; - - - - default: - throw new InputExceptions.InvalidCommandException(); - } - + Parser.parseCommand(userInput, taskList, storage, ui); } catch (InputExceptions e) { - System.out.println("Error: " + e.getMessage()); - System.out.println("____________________________________________________________"); - + System.out.println("Error: " + e.getMessage()); // Prints error but continues running } catch (NumberFormatException e) { System.out.println("Error: Please enter a valid number."); - System.out.println("____________________________________________________________"); } } + } + + + +// +// public void start() throws InputExceptions { +// System.out.println("____________________________________________________________"); +// ASCII_Art.printArt(); +// System.out.println(" Hello! I'm BobChungus "); +// System.out.println(" What can I do for you?"); +// System.out.println("____________________________________________________________"); +// +// try { +// loadFileContents(filepath); // Call method inside try block +// } catch (FileNotFoundException e) { +// System.err.println("Error: File not found. " + e.getMessage()); +// } +// +// while (true) { +// String input = scanner.nextLine().trim(); +// String[] inputParts = input.split(" ", 2); +// String command = inputParts[0].toLowerCase(); +// String arguments = (inputParts.length > 1) ? inputParts[1] : ""; +// +// try { +// switch (command) { +// case "bye": +// System.out.println("____________________________________________________________"); +// System.out.println(" Bye. Hope to see you again soon!"); +// System.out.println("____________________________________________________________"); +// saveFileContents(filepath); +// scanner.close(); +// return; +// +// case "list": +// System.out.println("____________________________________________________________"); +// System.out.println(" Here are the tasks in your list:"); +// if (tasks.isEmpty()) { +// System.out.println("No tasks added yet."); +// } else { +// for (int i = 0; i < tasks.size(); i++) { +// System.out.println((i + 1) + ". " + tasks.get(i).toString()); +// } +// } +// System.out.println("____________________________________________________________"); +// break; +// +// case "mark": +// if (arguments.isEmpty()) throw new InputExceptions.MissingArgumentException("mark"); +// int markIndex = Integer.parseInt(arguments) - 1; +// if (markIndex < 0 || markIndex >= tasks.size()) throw new InputExceptions("mark target must exist"); +// tasks.get(markIndex).markAsDone(); +// System.out.println("____________________________________________________________"); +// System.out.println(" Nice! I've marked this task as done:"); +// System.out.println(" " + tasks.get(markIndex).toString()); +// System.out.println("____________________________________________________________"); +// break; +// +// case "unmark": +// if (arguments.isEmpty()) throw new InputExceptions("unmark failed, no arguments"); +// int unmarkIndex = Integer.parseInt(arguments) - 1; +// if (unmarkIndex < 0 || unmarkIndex >= tasks.size()) +// throw new InputExceptions.InvalidIndexException(); +// tasks.get(unmarkIndex).markAsNotDone(); +// System.out.println("____________________________________________________________"); +// System.out.println(" OK, I've marked this task as not done yet:"); +// System.out.println(" " + tasks.get(unmarkIndex).toString()); +// System.out.println("____________________________________________________________"); +// break; +// +// case "todo": +// if (arguments.isEmpty()) { +// throw new InputExceptions.MissingArgumentException("todo"); +// } +// tasks.add( new ToDo(arguments) ); +// System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); +// System.out.println("____________________________________________________________"); +// break; +// +// case "deadline": +// String[] parts = arguments.split(" /by ", 2); +// if (parts.length < 2) throw new InputExceptions.MissingArgumentException("deadline"); +// tasks.add( new Deadline(parts[0], parts[1])); +// System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); +// System.out.println("____________________________________________________________"); +// break; +// +// case "event": +// String[] eventParts = arguments.split(" /from ", 2); +// if (eventParts.length < 2) throw new InputExceptions.MissingArgumentException("event"); +// String[] timeParts = eventParts[1].split(" /to ", 2); +// if (timeParts.length < 2) throw new InputExceptions.MissingArgumentException("event timing"); +// tasks.add( new Event(eventParts[0], timeParts[0], timeParts[1])); +// System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); +// System.out.println("____________________________________________________________"); +// break; +// +// case "delete": +// if (arguments.isEmpty()) { +// throw new InputExceptions.MissingArgumentException("todo"); +// } +// int deleteIndex = Integer.parseInt(arguments) - 1; +// if (deleteIndex < 0 || deleteIndex >= tasks.size()) { +// throw new InputExceptions.InvalidIndexException(); +// } +// Task removedTask = tasks.remove(deleteIndex); +// System.out.println("____________________________________________________________"); +// System.out.println(" Noted. I've removed this task:"); +// System.out.println(" " + removedTask); +// System.out.println("Now you have " + tasks.size() + " tasks in the list."); +// System.out.println("____________________________________________________________"); +// break; +// +// +// +// default: +// throw new InputExceptions.InvalidCommandException(); +// } +// +// } catch (InputExceptions e) { +// System.out.println("Error: " + e.getMessage()); +// System.out.println("____________________________________________________________"); +// +// } catch (NumberFormatException e) { +// System.out.println("Error: Please enter a valid number."); +// System.out.println("____________________________________________________________"); +// } +// } +// } + } public class BobChat { - public static void main(String[] args) throws InputExceptions { + public static void main(String[] args) throws InputExceptions, IOException { Bob chatbot = new Bob(); chatbot.start(); } } + + +// // Load tasks from file +// private static void loadFileContents(String filePath) throws FileNotFoundException { +// File file = new File(filePath); +// if (!file.exists()) { +// System.out.println("File does not exist, starting with an empty list."); +// return; +// } +// +// Scanner scanner = new Scanner(file); +// while (scanner.hasNextLine()) { +// String line = scanner.nextLine(); +// tasks.add(Task.fromString(line)); // Convert line to Task and add +// } +// scanner.close(); +// System.out.println("Tasks loaded successfully."); +// } +// +// // Save tasks to file +// private static void saveFileContents(String filePath) { +// try (FileWriter fileWriter = new FileWriter(filePath); +// PrintWriter writer = new PrintWriter(fileWriter)) { +// +// for (Task task : tasks) { +// writer.println(task); // Uses Task's toString() method +// } +// +// System.out.println("Tasks saved successfully."); +// } catch (IOException e) { +// System.err.println("Error saving tasks: " + e.getMessage()); +// } +// } \ No newline at end of file diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index aca72cd1d..b5eabfe63 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -8,6 +8,10 @@ public Deadline(String description, String deadlineBy) { System.out.println(this); } + public String getDeadlineBy() { + return deadlineBy; + } + @Override public String toString() { return "[D]" + getStatusIcon() + getDescription() + " (by: " + deadlineBy + ")"; diff --git a/src/main/java/Errors/InputExceptions.java b/src/main/java/Errors/InputExceptions.java index 05f5d044e..f64971d1c 100644 --- a/src/main/java/Errors/InputExceptions.java +++ b/src/main/java/Errors/InputExceptions.java @@ -1,13 +1,30 @@ package Errors; +import java.util.Objects; + public class InputExceptions extends Exception { public InputExceptions(String message) { super(message); } - public static class MissingArgumentException extends InputExceptions { - public MissingArgumentException(String command) { - super(command + " must have arguments."); + public static class MissingTodoArgumentException extends InputExceptions { + public MissingTodoArgumentException(String command) { + super(command + " must have arguments." + "\n" + + "Please use: \"todo\" \"task\" instead"); + } + } + + public static class MissingDeadlineArgumentException extends InputExceptions { + public MissingDeadlineArgumentException(String command) { + super(command + " must have arguments." + "\n" + + "Please use: \"deadline\" \"task\" /by \"deadline\" indead"); + } + } + + public static class MissingEventArgumentException extends InputExceptions { + public MissingEventArgumentException(String command) { + super(command + " must have arguments." + "\n" + + "Please use: \"event\" \"task\" /from \"eventfrom\" /to \"eventto\" instead"); } } @@ -23,9 +40,5 @@ public InvalidCommandException() { } } - public static class NumberFormatException extends InputExceptions { - public NumberFormatException() { - super("Error: Please enter a valid number."); - } - } + } \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 1ef9e3569..c29c67767 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -10,6 +10,14 @@ public Event(String description, String eventFrom, String eventTo) { System.out.println(this); } + public String getEventFrom() { + return eventFrom; + } + + public String getEventTo() { + return eventTo; + } + @Override public String toString() { return "[E]" + getStatusIcon() + getDescription() + " (from: " + eventFrom + " to: " + eventTo + ")"; diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 4d27fe15e..003d56b82 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,2 +1,61 @@ -public class Parser { -} +import Errors.InputExceptions; + + class Parser { + public static void parseCommand(String input, TaskList taskList, Storage storage, UI ui) throws InputExceptions { + String[] inputParts = input.split(" ", 2); + String command = inputParts[0].toLowerCase(); + String arguments = (inputParts.length > 1) ? inputParts[1] : ""; + + switch (command) { + case "bye": + ui.showGoodbye(); + storage.saveTasks(taskList.getTasks()); + System.exit(0); + break; + case "list": + ui.showList(); + if (taskList.size() == 0) { + System.out.println("No tasks added yet."); + } else { + for (int i = 0; i < taskList.size(); i++) { + System.out.println((i + 1) + ". " + taskList.getTask(i)); + } + } + ui.printLine(); + break; + + case "todo": + if (arguments.isEmpty()) { + throw new InputExceptions.MissingTodoArgumentException("todo"); + } + taskList.addTask(new ToDo(arguments)); + break; + + case "deadline": + String[] parts = arguments.split(" /by ", 2); + if (parts.length < 2) throw new InputExceptions.MissingDeadlineArgumentException("deadline"); + taskList.addTask(new Deadline(parts[0], parts[1])); + break; + + case "event": + String[] eventParts = arguments.split(" /from ", 2); + if (eventParts.length < 2) { + throw new InputExceptions.MissingEventArgumentException("event"); + } + String[] timeParts = eventParts[1].split(" /to ", 2); + + if (timeParts.length < 2) { + throw new InputExceptions.MissingEventArgumentException("event"); + } + taskList.addTask(new Event(eventParts[0], timeParts[0], timeParts[1])); + break; + + case "delete": + int deleteIndex = Integer.parseInt(arguments) - 1; + taskList.removeTask(deleteIndex); + break; + default: + throw new InputExceptions.InvalidCommandException(); + } + } +} \ No newline at end of file diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 56b3e6412..5e18f6a4a 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,19 +1,97 @@ -public class Storage { - private static String filePath = "data/userTasks.txt"; +import java.io.*; +import java.util.ArrayList; +import java.util.Scanner; +class Storage { + private final String filePath; - public void saveData(String data) { - // Implement file writing logic here + public Storage(String filePath) { + this.filePath = filePath; + } + + public ArrayList loadTasks() throws FileNotFoundException { + ArrayList tasks = new ArrayList<>(); + File file = new File(filePath); + if (!file.exists()) { + System.out.println("File does not exist, starting with an empty list."); + return tasks; + } + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + tasks.add(formatTaskFromStorage(scanner.nextLine())); + } + + scanner.close(); + System.out.println("Tasks loaded successfully."); + return tasks; + } + + public void saveTasks(ArrayList tasks) { + try (FileWriter fileWriter = new FileWriter(filePath); + PrintWriter writer = new PrintWriter(fileWriter)) { + for (Task task : tasks) { + String taskInStorageFormat = formatTaskToStorage(task); + writer.println(taskInStorageFormat); + } + System.out.println("Tasks saved successfully."); + } catch (IOException e) { + System.err.println("Error saving tasks: " + e.getMessage()); + } } - public String loadData() { - // Implement file reading logic here + public String formatTaskToStorage(Task task) { + String taskInStorageFormat; - return ""; // Return loaded data + if (task instanceof ToDo) { + taskInStorageFormat = "todo|" + task.getDescription(); + } + else if (task instanceof Deadline deadlineTask) { + // Cast task to Deadline + taskInStorageFormat = "deadline|" + deadlineTask.getDescription() + "|" + deadlineTask.getDeadlineBy(); + } + else if (task instanceof Event eventTask) { + // Cast task to Event + taskInStorageFormat = "event|" + eventTask.getDescription() + "|" + eventTask.getEventFrom() + "|" + eventTask.getEventTo(); + } + else { + throw new IllegalArgumentException("Unknown task type: " + task.getClass().getSimpleName()); + } + return taskInStorageFormat; } -} + public Task formatTaskFromStorage(String savedTask) { + String[] parts = savedTask.split("\\|"); // Split by "|" + + // Ensure the task format is valid + if (parts.length < 2) { + throw new IllegalArgumentException("Invalid task format: " + savedTask); + } + + String taskType = parts[0]; + String description = parts[1]; + + switch (taskType) { + case "todo": + return new ToDo(description); + + case "deadline": + if (parts.length < 3) { + throw new IllegalArgumentException("Invalid deadline format: " + savedTask); + } + return new Deadline(description, parts[2]); + + case "event": + if (parts.length < 4) { + throw new IllegalArgumentException("Invalid event format: " + savedTask); + } + return new Event(description, parts[2], parts[3]); + + default: + throw new IllegalArgumentException("Unknown task type: " + taskType); + } + } +} \ No newline at end of file diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 1e7aed1c0..be0509cea 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,2 +1,34 @@ -public class TaskList { +import Errors.InputExceptions; + +import java.util.ArrayList; + +class TaskList { + private final ArrayList tasks; + + public TaskList(ArrayList tasks) { + this.tasks = tasks; + } + + public void addTask(Task task) { + tasks.add(task); + } + + public Task removeTask(int index) throws InputExceptions.InvalidIndexException { + if (index < 0 || index >= tasks.size()) { + throw new InputExceptions.InvalidIndexException(); + } + return tasks.remove(index); + } + + public Task getTask(int index) { + return tasks.get(index); + } + + public int size() { + return tasks.size(); + } + + public ArrayList getTasks() { + return tasks; + } } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 667400c3f..7c0207f4f 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,5 +1,37 @@ -public class Ui { +import java.util.Scanner; +class UI { + private final Scanner scanner = new Scanner(System.in); + public void showWelcome() { + System.out.println("____________________________________________________________"); + ASCII_Art.printArt(); + System.out.println(" Hello! I'm BobChungus "); + System.out.println(" What can I do for you?"); + System.out.println("____________________________________________________________"); + } + public void showGoodbye() { + System.out.println("____________________________________________________________"); + System.out.println(" Bye. Hope to see you again soon!"); + System.out.println("____________________________________________________________"); + } + + public void showError(String message) { + System.out.println("Error: " + message); + System.out.println("____________________________________________________________"); + } + + public void showList() { + System.out.println("____________________________________________________________"); + System.out.println(" Here are the tasks in your list:"); + } + + public void printLine() { + System.out.println("____________________________________________________________"); + } + + public String getUserInput() { + return scanner.nextLine().trim(); + } } From c5ef62831ab60fe24eaa8e2c8d9485e23fe3a5ac Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Sat, 8 Mar 2025 19:58:02 +0800 Subject: [PATCH 15/31] A-Assertions --- src/main/java/BobChat.java | 2 +- src/main/java/Storage.java | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index 3f013a7d9..1fba25160 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -19,7 +19,7 @@ class Bob { // static final ArrayList tasks = new ArrayList<>(); - public void start() throws InputExceptions { + public void start() { ui.showWelcome(); while (true) { String userInput = ui.getUserInput(); diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 5e18f6a4a..1149eb631 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -45,18 +45,18 @@ public String formatTaskToStorage(Task task) { if (task instanceof ToDo) { taskInStorageFormat = "todo|" + task.getDescription(); - } - else if (task instanceof Deadline deadlineTask) { - // Cast task to Deadline + } else if (task instanceof Deadline deadlineTask) { + // Assert Task as Deadline taskInStorageFormat = "deadline|" + deadlineTask.getDescription() + "|" + deadlineTask.getDeadlineBy(); - } - else if (task instanceof Event eventTask) { + } else if (task instanceof Event eventTask) { // Cast task to Event taskInStorageFormat = "event|" + eventTask.getDescription() + "|" + eventTask.getEventFrom() + "|" + eventTask.getEventTo(); - } - else { + } else { throw new IllegalArgumentException("Unknown task type: " + task.getClass().getSimpleName()); } + + assert taskInStorageFormat != null : "taskInStorageFormat should not be null"; + return taskInStorageFormat; } @@ -73,16 +73,19 @@ public Task formatTaskFromStorage(String savedTask) { switch (taskType) { case "todo": + assert parts.length == 2 : "Todo task should have 2 arguments"; return new ToDo(description); case "deadline": - if (parts.length < 3) { + assert parts.length == 3 : "Deadline task should have 3 arguments"; + if (parts.length != 3) { throw new IllegalArgumentException("Invalid deadline format: " + savedTask); } return new Deadline(description, parts[2]); case "event": - if (parts.length < 4) { + assert parts.length == 4 : "Event task should have 4 arguments"; + if (parts.length != 4) { throw new IllegalArgumentException("Invalid event format: " + savedTask); } return new Event(description, parts[2], parts[3]); From 5c4b5e55c552cac5f30c0718bde2b36e74be5c0f Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Sat, 8 Mar 2025 20:23:45 +0800 Subject: [PATCH 16/31] A-CodeQuality --- src/main/java/BobChat.java | 175 +----------------------------------- src/main/java/Deadline.java | 1 + src/main/java/Parser.java | 15 +++- src/main/java/Storage.java | 2 - src/main/java/TaskList.java | 16 ++-- src/main/java/Ui.java | 9 -- 6 files changed, 26 insertions(+), 192 deletions(-) diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index 3f013a7d9..9011e521a 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -1,6 +1,4 @@ import java.io.*; -//import java.util.ArrayList; -//import java.util.Scanner; import Errors.*; @@ -9,21 +7,16 @@ class Bob { Bob() throws FileNotFoundException { } -// private final Scanner scanner = new Scanner(System.in); private final UI ui = new UI(); private final Storage storage = new Storage("data/userTasks.txt"); - private final TaskList taskList = new TaskList( storage.loadTasks()); - - -// private final String filepath = "data/userTasks.txt"; -// static final ArrayList tasks = new ArrayList<>(); + private final TaskList taskList = new TaskList(storage.loadTasks()); public void start() throws InputExceptions { ui.showWelcome(); + while (true) { - String userInput = ui.getUserInput(); -// Parser.parseCommand(userInput, taskList, storage, ui); + String userInput = Parser.getUserInput(); try { Parser.parseCommand(userInput, taskList, storage, ui); } catch (InputExceptions e) { @@ -34,136 +27,6 @@ public void start() throws InputExceptions { } } - - - - -// -// public void start() throws InputExceptions { -// System.out.println("____________________________________________________________"); -// ASCII_Art.printArt(); -// System.out.println(" Hello! I'm BobChungus "); -// System.out.println(" What can I do for you?"); -// System.out.println("____________________________________________________________"); -// -// try { -// loadFileContents(filepath); // Call method inside try block -// } catch (FileNotFoundException e) { -// System.err.println("Error: File not found. " + e.getMessage()); -// } -// -// while (true) { -// String input = scanner.nextLine().trim(); -// String[] inputParts = input.split(" ", 2); -// String command = inputParts[0].toLowerCase(); -// String arguments = (inputParts.length > 1) ? inputParts[1] : ""; -// -// try { -// switch (command) { -// case "bye": -// System.out.println("____________________________________________________________"); -// System.out.println(" Bye. Hope to see you again soon!"); -// System.out.println("____________________________________________________________"); -// saveFileContents(filepath); -// scanner.close(); -// return; -// -// case "list": -// System.out.println("____________________________________________________________"); -// System.out.println(" Here are the tasks in your list:"); -// if (tasks.isEmpty()) { -// System.out.println("No tasks added yet."); -// } else { -// for (int i = 0; i < tasks.size(); i++) { -// System.out.println((i + 1) + ". " + tasks.get(i).toString()); -// } -// } -// System.out.println("____________________________________________________________"); -// break; -// -// case "mark": -// if (arguments.isEmpty()) throw new InputExceptions.MissingArgumentException("mark"); -// int markIndex = Integer.parseInt(arguments) - 1; -// if (markIndex < 0 || markIndex >= tasks.size()) throw new InputExceptions("mark target must exist"); -// tasks.get(markIndex).markAsDone(); -// System.out.println("____________________________________________________________"); -// System.out.println(" Nice! I've marked this task as done:"); -// System.out.println(" " + tasks.get(markIndex).toString()); -// System.out.println("____________________________________________________________"); -// break; -// -// case "unmark": -// if (arguments.isEmpty()) throw new InputExceptions("unmark failed, no arguments"); -// int unmarkIndex = Integer.parseInt(arguments) - 1; -// if (unmarkIndex < 0 || unmarkIndex >= tasks.size()) -// throw new InputExceptions.InvalidIndexException(); -// tasks.get(unmarkIndex).markAsNotDone(); -// System.out.println("____________________________________________________________"); -// System.out.println(" OK, I've marked this task as not done yet:"); -// System.out.println(" " + tasks.get(unmarkIndex).toString()); -// System.out.println("____________________________________________________________"); -// break; -// -// case "todo": -// if (arguments.isEmpty()) { -// throw new InputExceptions.MissingArgumentException("todo"); -// } -// tasks.add( new ToDo(arguments) ); -// System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); -// System.out.println("____________________________________________________________"); -// break; -// -// case "deadline": -// String[] parts = arguments.split(" /by ", 2); -// if (parts.length < 2) throw new InputExceptions.MissingArgumentException("deadline"); -// tasks.add( new Deadline(parts[0], parts[1])); -// System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); -// System.out.println("____________________________________________________________"); -// break; -// -// case "event": -// String[] eventParts = arguments.split(" /from ", 2); -// if (eventParts.length < 2) throw new InputExceptions.MissingArgumentException("event"); -// String[] timeParts = eventParts[1].split(" /to ", 2); -// if (timeParts.length < 2) throw new InputExceptions.MissingArgumentException("event timing"); -// tasks.add( new Event(eventParts[0], timeParts[0], timeParts[1])); -// System.out.println("Now you have " + (tasks.size()) + " tasks in the list."); -// System.out.println("____________________________________________________________"); -// break; -// -// case "delete": -// if (arguments.isEmpty()) { -// throw new InputExceptions.MissingArgumentException("todo"); -// } -// int deleteIndex = Integer.parseInt(arguments) - 1; -// if (deleteIndex < 0 || deleteIndex >= tasks.size()) { -// throw new InputExceptions.InvalidIndexException(); -// } -// Task removedTask = tasks.remove(deleteIndex); -// System.out.println("____________________________________________________________"); -// System.out.println(" Noted. I've removed this task:"); -// System.out.println(" " + removedTask); -// System.out.println("Now you have " + tasks.size() + " tasks in the list."); -// System.out.println("____________________________________________________________"); -// break; -// -// -// -// default: -// throw new InputExceptions.InvalidCommandException(); -// } -// -// } catch (InputExceptions e) { -// System.out.println("Error: " + e.getMessage()); -// System.out.println("____________________________________________________________"); -// -// } catch (NumberFormatException e) { -// System.out.println("Error: Please enter a valid number."); -// System.out.println("____________________________________________________________"); -// } -// } -// } - } public class BobChat { @@ -174,34 +37,4 @@ public static void main(String[] args) throws InputExceptions, IOException { } -// // Load tasks from file -// private static void loadFileContents(String filePath) throws FileNotFoundException { -// File file = new File(filePath); -// if (!file.exists()) { -// System.out.println("File does not exist, starting with an empty list."); -// return; -// } -// -// Scanner scanner = new Scanner(file); -// while (scanner.hasNextLine()) { -// String line = scanner.nextLine(); -// tasks.add(Task.fromString(line)); // Convert line to Task and add -// } -// scanner.close(); -// System.out.println("Tasks loaded successfully."); -// } -// -// // Save tasks to file -// private static void saveFileContents(String filePath) { -// try (FileWriter fileWriter = new FileWriter(filePath); -// PrintWriter writer = new PrintWriter(fileWriter)) { -// -// for (Task task : tasks) { -// writer.println(task); // Uses Task's toString() method -// } -// -// System.out.println("Tasks saved successfully."); -// } catch (IOException e) { -// System.err.println("Error saving tasks: " + e.getMessage()); -// } -// } \ No newline at end of file + diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index b5eabfe63..86613acec 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,6 +1,7 @@ class Deadline extends Task { private final String deadlineBy; + public Deadline(String description, String deadlineBy) { super(description); this.deadlineBy = deadlineBy; diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 003d56b82..776501414 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,6 +1,13 @@ import Errors.InputExceptions; - class Parser { +import java.util.Scanner; + +class Parser { + private static final Scanner scanner = new Scanner(System.in); + public static String getUserInput() { + return scanner.nextLine().trim(); + } + public static void parseCommand(String input, TaskList taskList, Storage storage, UI ui) throws InputExceptions { String[] inputParts = input.split(" ", 2); String command = inputParts[0].toLowerCase(); @@ -9,7 +16,7 @@ public static void parseCommand(String input, TaskList taskList, Storage storage switch (command) { case "bye": ui.showGoodbye(); - storage.saveTasks(taskList.getTasks()); + storage.saveTasks(taskList.getListOfTasks()); System.exit(0); break; case "list": @@ -58,4 +65,6 @@ public static void parseCommand(String input, TaskList taskList, Storage storage throw new InputExceptions.InvalidCommandException(); } } -} \ No newline at end of file + + + } \ No newline at end of file diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 5e18f6a4a..46a1d5aa3 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -47,11 +47,9 @@ public String formatTaskToStorage(Task task) { taskInStorageFormat = "todo|" + task.getDescription(); } else if (task instanceof Deadline deadlineTask) { - // Cast task to Deadline taskInStorageFormat = "deadline|" + deadlineTask.getDescription() + "|" + deadlineTask.getDeadlineBy(); } else if (task instanceof Event eventTask) { - // Cast task to Event taskInStorageFormat = "event|" + eventTask.getDescription() + "|" + eventTask.getEventFrom() + "|" + eventTask.getEventTo(); } else { diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index be0509cea..129bcdf2d 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,5 +1,4 @@ import Errors.InputExceptions; - import java.util.ArrayList; class TaskList { @@ -13,22 +12,25 @@ public void addTask(Task task) { tasks.add(task); } - public Task removeTask(int index) throws InputExceptions.InvalidIndexException { + public Task getTask(int index) throws InputExceptions { if (index < 0 || index >= tasks.size()) { throw new InputExceptions.InvalidIndexException(); } - return tasks.remove(index); + return tasks.get(index); } - public Task getTask(int index) { - return tasks.get(index); + public ArrayList getListOfTasks() { + return tasks; } public int size() { return tasks.size(); } - public ArrayList getTasks() { - return tasks; + public void removeTask(int index) throws InputExceptions { + if (index < 0 || index >= tasks.size()) { + throw new InputExceptions.InvalidIndexException(); + } + tasks.remove(index); } } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 7c0207f4f..7363a82c8 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,7 +1,6 @@ import java.util.Scanner; class UI { - private final Scanner scanner = new Scanner(System.in); public void showWelcome() { System.out.println("____________________________________________________________"); @@ -17,11 +16,6 @@ public void showGoodbye() { System.out.println("____________________________________________________________"); } - public void showError(String message) { - System.out.println("Error: " + message); - System.out.println("____________________________________________________________"); - } - public void showList() { System.out.println("____________________________________________________________"); System.out.println(" Here are the tasks in your list:"); @@ -31,7 +25,4 @@ public void printLine() { System.out.println("____________________________________________________________"); } - public String getUserInput() { - return scanner.nextLine().trim(); - } } From c17a112a282d6b75e9843c11dc590351aeccdf3e Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Sat, 8 Mar 2025 23:59:48 +0800 Subject: [PATCH 17/31] added level-8 --- data/userTasks.txt | 5 ++- src/main/java/Deadline.java | 10 +++-- src/main/java/Errors/InputExceptions.java | 5 +++ src/main/java/Event.java | 16 +++++--- src/main/java/Parser.java | 45 ++++++++++++++++++++--- src/main/java/Storage.java | 45 ++++++++++++++++------- src/main/java/Task.java | 11 ++++-- src/main/java/ToDo.java | 3 +- src/main/java/Ui.java | 19 +++++++++- 9 files changed, 127 insertions(+), 32 deletions(-) diff --git a/data/userTasks.txt b/data/userTasks.txt index d8e8e105a..fced1385d 100644 --- a/data/userTasks.txt +++ b/data/userTasks.txt @@ -1 +1,4 @@ -todo|do homework +event|testing|12/12/2022|31/01/2024 +deadline|testing2|11/11/2024 +todo|test +todo|test diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 86613acec..6e1a1df56 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,16 +1,20 @@ +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; class Deadline extends Task { - private final String deadlineBy; + private final LocalDate deadlineBy; + private final DateTimeFormatter dateTimeOutputFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy"); - public Deadline(String description, String deadlineBy) { + public Deadline(boolean isDone, String description, LocalDate deadlineBy) { super(description); + this.isDone = isDone; this.deadlineBy = deadlineBy; System.out.println("I have added this deadline: "); System.out.println(this); } public String getDeadlineBy() { - return deadlineBy; + return deadlineBy.format(dateTimeOutputFormat); } @Override diff --git a/src/main/java/Errors/InputExceptions.java b/src/main/java/Errors/InputExceptions.java index f64971d1c..1765c36bf 100644 --- a/src/main/java/Errors/InputExceptions.java +++ b/src/main/java/Errors/InputExceptions.java @@ -40,5 +40,10 @@ public InvalidCommandException() { } } + public static class InvalidDateFormatException extends InputExceptions { + public InvalidDateFormatException() { + super("Invalid date format. Please use dd-MM-yyyy."); + } + } } \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java index c29c67767..b30b3854c 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,9 +1,15 @@ +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + class Event extends Task { - private final String eventFrom; - private final String eventTo; + private final LocalDate eventFrom; + private final LocalDate eventTo; + private final DateTimeFormatter dateTimeOutputFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + - public Event(String description, String eventFrom, String eventTo) { + public Event(boolean isDone, String description, LocalDate eventFrom, LocalDate eventTo) { super(description); + this.isDone = isDone; this.eventFrom = eventFrom; this.eventTo = eventTo; System.out.println("I have added this event: "); @@ -11,11 +17,11 @@ public Event(String description, String eventFrom, String eventTo) { } public String getEventFrom() { - return eventFrom; + return eventFrom.format(dateTimeOutputFormat); } public String getEventTo() { - return eventTo; + return eventTo.format(dateTimeOutputFormat); } @Override diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 776501414..229dc33d1 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -1,9 +1,13 @@ import Errors.InputExceptions; - import java.util.Scanner; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; class Parser { private static final Scanner scanner = new Scanner(System.in); + private static final DateTimeFormatter dateTimeInputFormat = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + public static String getUserInput() { return scanner.nextLine().trim(); } @@ -19,6 +23,7 @@ public static void parseCommand(String input, TaskList taskList, Storage storage storage.saveTasks(taskList.getListOfTasks()); System.exit(0); break; + case "list": ui.showList(); if (taskList.size() == 0) { @@ -35,13 +40,23 @@ public static void parseCommand(String input, TaskList taskList, Storage storage if (arguments.isEmpty()) { throw new InputExceptions.MissingTodoArgumentException("todo"); } - taskList.addTask(new ToDo(arguments)); + taskList.addTask(new ToDo(false, arguments)); + ui.printLine(); break; case "deadline": String[] parts = arguments.split(" /by ", 2); - if (parts.length < 2) throw new InputExceptions.MissingDeadlineArgumentException("deadline"); - taskList.addTask(new Deadline(parts[0], parts[1])); + if (parts.length < 2) { + throw new InputExceptions.MissingDeadlineArgumentException("deadline"); + } + + try { + LocalDate deadlineBy = LocalDate.parse(parts[1], dateTimeInputFormat); + taskList.addTask(new Deadline(false, parts[0], deadlineBy)); + } catch (DateTimeParseException e) { + throw new InputExceptions.InvalidDateFormatException(); + } + ui.printLine(); break; case "event": @@ -54,12 +69,32 @@ public static void parseCommand(String input, TaskList taskList, Storage storage if (timeParts.length < 2) { throw new InputExceptions.MissingEventArgumentException("event"); } - taskList.addTask(new Event(eventParts[0], timeParts[0], timeParts[1])); + try { + LocalDate startDate = LocalDate.parse(timeParts[0], dateTimeInputFormat); + LocalDate endDate = LocalDate.parse(timeParts[1], dateTimeInputFormat); + taskList.addTask(new Event(false, eventParts[0], startDate, endDate)); + } catch (DateTimeParseException e) { + throw new InputExceptions.InvalidDateFormatException(); + } + ui.printLine(); break; case "delete": int deleteIndex = Integer.parseInt(arguments) - 1; taskList.removeTask(deleteIndex); + ui.deletedTask(deleteIndex); + break; + + case "mark": + int markIndex = Integer.parseInt(arguments) - 1; + taskList.getTask(markIndex).markAsDone(); + ui.markedTask(markIndex); + break; + + case "unmark": + int unmarkIndex = Integer.parseInt(arguments) - 1; + taskList.getTask(unmarkIndex).markAsNotDone(); + ui.unmarkedTask(unmarkIndex); break; default: throw new InputExceptions.InvalidCommandException(); diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 11198553a..0f0616560 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,7 +1,11 @@ import java.io.*; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Objects; import java.util.Scanner; + class Storage { private final String filePath; @@ -43,15 +47,18 @@ public void saveTasks(ArrayList tasks) { public String formatTaskToStorage(Task task) { String taskInStorageFormat; + if (task instanceof ToDo) { - taskInStorageFormat = "todo|" + task.getDescription(); + taskInStorageFormat = "todo|" + task.getDoneStatus() + "|" + task.getDescription(); } else if (task instanceof Deadline deadlineTask) { - taskInStorageFormat = "deadline|" + deadlineTask.getDescription() + "|" + deadlineTask.getDeadlineBy(); + taskInStorageFormat = "deadline|" + deadlineTask.getDoneStatus() + "|" + deadlineTask.getDescription() + + "|" + deadlineTask.getDeadlineBy(); } else if (task instanceof Event eventTask) { - taskInStorageFormat = "event|" + eventTask.getDescription() + "|" + eventTask.getEventFrom() + "|" + eventTask.getEventTo(); + taskInStorageFormat = "event|" + eventTask.getDoneStatus() + "|" + eventTask.getDescription() + + "|" + eventTask.getEventFrom() + "|" + eventTask.getEventTo(); } else { throw new IllegalArgumentException("Unknown task type: " + task.getClass().getSimpleName()); } @@ -63,33 +70,45 @@ else if (task instanceof Event eventTask) { public Task formatTaskFromStorage(String savedTask) { String[] parts = savedTask.split("\\|"); // Split by "|" + DateTimeFormatter dateTimeLoadFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy"); // Ensure the task format is valid - if (parts.length < 2) { + if (parts.length < 3) { throw new IllegalArgumentException("Invalid task format: " + savedTask); } String taskType = parts[0]; - String description = parts[1]; + String taskDoneFormat = parts[1]; + String description = parts[2]; + + boolean taskDone; + + if (Objects.equals(taskDoneFormat, "done")){ + taskDone = true; + } else if (Objects.equals(taskDoneFormat, "not done")){ + taskDone = false; + } else { + throw new IllegalArgumentException("Data corrupted" + savedTask); + } switch (taskType) { case "todo": - assert parts.length == 2 : "Todo task should have 2 arguments"; - return new ToDo(description); + assert parts.length == 3 : "Todo task should have 2 arguments"; + return new ToDo(taskDone, description); case "deadline": - assert parts.length == 3 : "Deadline task should have 3 arguments"; - if (parts.length != 3) { + assert parts.length == 4 : "Deadline task should have 3 arguments"; + if (parts.length != 4) { throw new IllegalArgumentException("Invalid deadline format: " + savedTask); } - return new Deadline(description, parts[2]); + return new Deadline(taskDone, description, LocalDate.parse(parts[3], dateTimeLoadFormat)); case "event": - assert parts.length == 4 : "Event task should have 4 arguments"; - if (parts.length != 4) { + assert parts.length == 5 : "Event task should have 4 arguments"; + if (parts.length != 5) { throw new IllegalArgumentException("Invalid event format: " + savedTask); } - return new Event(description, parts[2], parts[3]); + return new Event(taskDone, description, LocalDate.parse(parts[3], dateTimeLoadFormat), LocalDate.parse(parts[4],dateTimeLoadFormat)); default: throw new IllegalArgumentException("Unknown task type: " + taskType); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 362c410de..a60a85382 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -7,9 +7,9 @@ public Task(String description) { this.isDone = false; } - public static Task fromString(String line) { - String[] parts = line.split("\n"); - return new Task(parts[0]); + public Task(boolean isDone, String description) { + this.isDone = isDone; + this.description = description; } public void markAsDone() { @@ -24,6 +24,11 @@ public String getStatusIcon() { return (isDone ? "[X] " : "[ ] "); } + public String getDoneStatus(){ + return (isDone ? "done" : "not done"); + } + + public String getDescription() { return description; } diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index 5b9fafb9b..a1448f147 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -1,6 +1,7 @@ public class ToDo extends Task { - public ToDo(String description) { + public ToDo(boolean isDone, String description) { super(description); + this.isDone = isDone; System.out.println("I have added this Todo: "); System.out.println(this); } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 7363a82c8..46d0bd191 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,4 +1,3 @@ -import java.util.Scanner; class UI { @@ -21,6 +20,24 @@ public void showList() { System.out.println(" Here are the tasks in your list:"); } + public void deletedTask(int deleteIndex){ + System.out.println("____________________________________________________________"); + System.out.println("Okay, deleted Task " + (deleteIndex + 1)); + System.out.println("____________________________________________________________"); + } + + public void markedTask(int markIndex){ + System.out.println("____________________________________________________________"); + System.out.println("Okay, marked Task " + (markIndex + 1)); + System.out.println("____________________________________________________________"); + } + + public void unmarkedTask(int unmarkIndex){ + System.out.println("____________________________________________________________"); + System.out.println("Okay, unmarked Task " + (unmarkIndex + 1)); + System.out.println("____________________________________________________________"); + } + public void printLine() { System.out.println("____________________________________________________________"); } From 6cf9f403361b9e13cd1ffe968d65dfca9f4318e7 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 00:49:39 +0800 Subject: [PATCH 18/31] Level-9 --- data/userTasks.txt | 5 +---- src/main/java/Errors/InputExceptions.java | 11 ++++++++--- src/main/java/Parser.java | 24 +++++++++++++++++++++++ src/main/java/Ui.java | 15 ++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/data/userTasks.txt b/data/userTasks.txt index fced1385d..81a72365c 100644 --- a/data/userTasks.txt +++ b/data/userTasks.txt @@ -1,4 +1 @@ -event|testing|12/12/2022|31/01/2024 -deadline|testing2|11/11/2024 -todo|test -todo|test +todo|done|testing diff --git a/src/main/java/Errors/InputExceptions.java b/src/main/java/Errors/InputExceptions.java index 1765c36bf..1d5f64045 100644 --- a/src/main/java/Errors/InputExceptions.java +++ b/src/main/java/Errors/InputExceptions.java @@ -1,7 +1,5 @@ package Errors; -import java.util.Objects; - public class InputExceptions extends Exception { public InputExceptions(String message) { super(message); @@ -17,7 +15,7 @@ public MissingTodoArgumentException(String command) { public static class MissingDeadlineArgumentException extends InputExceptions { public MissingDeadlineArgumentException(String command) { super(command + " must have arguments." + "\n" + - "Please use: \"deadline\" \"task\" /by \"deadline\" indead"); + "Please use: \"deadline\" \"task\" /by \"deadline\" instead"); } } @@ -28,6 +26,13 @@ public MissingEventArgumentException(String command) { } } + public static class MissingFindArgumentException extends InputExceptions { + public MissingFindArgumentException(String command) { + super(command + " must contain 1 argument." + "\n" + + "Please use: \"find\" \"description\" instead"); + } + } + public static class InvalidIndexException extends InputExceptions { public InvalidIndexException() { super("Invalid task number."); diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 229dc33d1..7c3a079e4 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -96,6 +96,30 @@ public static void parseCommand(String input, TaskList taskList, Storage storage taskList.getTask(unmarkIndex).markAsNotDone(); ui.unmarkedTask(unmarkIndex); break; + + case "find": + if (arguments.isEmpty()) { + throw new InputExceptions.MissingFindArgumentException("find"); + } + + ui.printFindingTask(); + + int taskFound = 0; + for (int i = 0; i < taskList.size(); i++) { + Task task = taskList.getTask(i); + if (task.getDescription().toLowerCase().contains(arguments)) { + taskFound++; + ui.printFoundTask(taskFound, task); + } + } + + if (taskFound == 0) { + ui.printNoTaskFound(); + } + + ui.printLine(); + + break; default: throw new InputExceptions.InvalidCommandException(); } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 46d0bd191..4c0786df0 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -38,6 +38,21 @@ public void unmarkedTask(int unmarkIndex){ System.out.println("____________________________________________________________"); } + public void printFindingTask(){ + System.out.println("____________________________________________________________"); + System.out.println("Here are the matching tasks in your list:"); + } + + public void printNoTaskFound(){ + printLine(); + System.out.println("No task with matching keyword found"); + } + + public void printFoundTask(int position, Task task){ + printLine(); + System.out.println( position + "." + " " + task.toString() ); + } + public void printLine() { System.out.println("____________________________________________________________"); } From ff5d6c7594310c4800e50a0a8f2cc8e1a8c29a19 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 08:43:21 +0800 Subject: [PATCH 19/31] Added A-JavaDoc --- src/main/java/BobChat.java | 29 +++++++++++++++++++++++-- src/main/java/Deadline.java | 20 +++++++++++++++++ src/main/java/Event.java | 28 +++++++++++++++++++++++- src/main/java/Parser.java | 26 +++++++++++++++++----- src/main/java/Storage.java | 37 +++++++++++++++++++++++++++++-- src/main/java/Task.java | 41 +++++++++++++++++++++++++++++++++-- src/main/java/TaskList.java | 37 +++++++++++++++++++++++++++++++ src/main/java/ToDo.java | 35 +++++++++++++++++++++--------- src/main/java/Ui.java | 43 ++++++++++++++++++++++++++++++++++++- 9 files changed, 273 insertions(+), 23 deletions(-) diff --git a/src/main/java/BobChat.java b/src/main/java/BobChat.java index 3ee54a290..a7bc62e75 100644 --- a/src/main/java/BobChat.java +++ b/src/main/java/BobChat.java @@ -1,17 +1,31 @@ import java.io.*; import Errors.*; - +/** + * Represents the Bob chatbot application, handling user input and task management. + */ class Bob { + /** + * Constructs a Bob chatbot instance and initializes necessary components. + * + * @throws FileNotFoundException If the task storage file is not found. + */ Bob() throws FileNotFoundException { } + /** User interface for interacting with the user. */ private final UI ui = new UI(); + + /** Storage handler for saving and loading tasks from a file. */ private final Storage storage = new Storage("data/userTasks.txt"); - private final TaskList taskList = new TaskList(storage.loadTasks()); + /** Task list containing all user tasks. */ + private final TaskList taskList = new TaskList(storage.loadTasks()); + /** + * Starts the chatbot, displaying a welcome message and handling user input continuously. + */ public void start() { ui.showWelcome(); @@ -29,7 +43,18 @@ public void start() { } } + +/** + * Entry point for running the Bob chatbot application. + */ public class BobChat { + /** + * Main method that initializes and starts the chatbot. + * + * @param args Command-line arguments. + * @throws InputExceptions If an input-related exception occurs. + * @throws IOException If an error occurs during file operations. + */ public static void main(String[] args) throws InputExceptions, IOException { Bob chatbot = new Bob(); chatbot.start(); diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 6e1a1df56..a8d22491d 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,10 +1,20 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; +/** + * The Deadline class represents a task with a specific due date. + */ class Deadline extends Task { private final LocalDate deadlineBy; private final DateTimeFormatter dateTimeOutputFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + /** + * Constructs a Deadline task with a description, completion status, and due date. + * + * @param isDone The completion status of the deadline task. + * @param description The description of the task. + * @param deadlineBy The due date of the task. + */ public Deadline(boolean isDone, String description, LocalDate deadlineBy) { super(description); this.isDone = isDone; @@ -13,10 +23,20 @@ public Deadline(boolean isDone, String description, LocalDate deadlineBy) { System.out.println(this); } + /** + * Gets the formatted due date of the deadline task. + * + * @return The formatted due date. + */ public String getDeadlineBy() { return deadlineBy.format(dateTimeOutputFormat); } + /** + * Returns a string representation of the Deadline task. + * + * @return The formatted string representation of the deadline task. + */ @Override public String toString() { return "[D]" + getStatusIcon() + getDescription() + " (by: " + deadlineBy + ")"; diff --git a/src/main/java/Event.java b/src/main/java/Event.java index b30b3854c..fb2e7884b 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,12 +1,22 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; +/** + * The Event class represents a task with a start and end date. + */ class Event extends Task { private final LocalDate eventFrom; private final LocalDate eventTo; private final DateTimeFormatter dateTimeOutputFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy"); - + /** + * Constructs an Event task with a description, completion status, start date, and end date. + * + * @param isDone The completion status of the event. + * @param description The description of the event. + * @param eventFrom The start date of the event. + * @param eventTo The end date of the event. + */ public Event(boolean isDone, String description, LocalDate eventFrom, LocalDate eventTo) { super(description); this.isDone = isDone; @@ -16,14 +26,30 @@ public Event(boolean isDone, String description, LocalDate eventFrom, LocalDate System.out.println(this); } + /** + * Gets the formatted start date of the event. + * + * @return The formatted start date. + */ public String getEventFrom() { return eventFrom.format(dateTimeOutputFormat); } + /** + * Gets the formatted end date of the event. + * + * @return The formatted end date. + */ public String getEventTo() { return eventTo.format(dateTimeOutputFormat); } + + /** + * Returns a string representation of the Event task. + * + * @return The formatted string representation of the event. + */ @Override public String toString() { return "[E]" + getStatusIcon() + getDescription() + " (from: " + eventFrom + " to: " + eventTo + ")"; diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 7c3a079e4..1a5f452b9 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -4,14 +4,34 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; + +/** + * Parses user commands and executes corresponding actions. + */ class Parser { + + /** Scanner for reading user input. */ private static final Scanner scanner = new Scanner(System.in); private static final DateTimeFormatter dateTimeInputFormat = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + /** + * Reads and returns user input from the console, trimming whitespace. + * + * @return The trimmed user input as a string. + */ public static String getUserInput() { return scanner.nextLine().trim(); } + /** + * Parses and executes the user command. + * + * @param input The user input string. + * @param taskList The list of tasks. + * @param storage The storage handler for saving tasks. + * @param ui The user interface handler for displaying messages. + * @throws InputExceptions If an invalid command or missing argument is encountered. + */ public static void parseCommand(String input, TaskList taskList, Storage storage, UI ui) throws InputExceptions { String[] inputParts = input.split(" ", 2); String command = inputParts[0].toLowerCase(); @@ -49,7 +69,6 @@ public static void parseCommand(String input, TaskList taskList, Storage storage if (parts.length < 2) { throw new InputExceptions.MissingDeadlineArgumentException("deadline"); } - try { LocalDate deadlineBy = LocalDate.parse(parts[1], dateTimeInputFormat); taskList.addTask(new Deadline(false, parts[0], deadlineBy)); @@ -65,7 +84,6 @@ public static void parseCommand(String input, TaskList taskList, Storage storage throw new InputExceptions.MissingEventArgumentException("event"); } String[] timeParts = eventParts[1].split(" /to ", 2); - if (timeParts.length < 2) { throw new InputExceptions.MissingEventArgumentException("event"); } @@ -101,9 +119,7 @@ public static void parseCommand(String input, TaskList taskList, Storage storage if (arguments.isEmpty()) { throw new InputExceptions.MissingFindArgumentException("find"); } - ui.printFindingTask(); - int taskFound = 0; for (int i = 0; i < taskList.size(); i++) { Task task = taskList.getTask(i); @@ -118,8 +134,8 @@ public static void parseCommand(String input, TaskList taskList, Storage storage } ui.printLine(); - break; + default: throw new InputExceptions.InvalidCommandException(); } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 0f0616560..b5845571e 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -5,14 +5,29 @@ import java.util.Objects; import java.util.Scanner; - +/** + * The Storage class handles loading and saving tasks to a file. + * It reads from and writes to a specified file path, ensuring tasks are + * persisted across program executions. + */ class Storage { private final String filePath; + /** + * Constructs a Storage object with a specified file path. + * + * @param filePath The path to the file where tasks are stored. + */ public Storage(String filePath) { this.filePath = filePath; } + /** + * Loads tasks from the file into an ArrayList. + * + * @return An ArrayList of tasks loaded from storage. + * @throws FileNotFoundException If the file does not exist. + */ public ArrayList loadTasks() throws FileNotFoundException { ArrayList tasks = new ArrayList<>(); File file = new File(filePath); @@ -30,6 +45,12 @@ public ArrayList loadTasks() throws FileNotFoundException { return tasks; } + + /** + * Saves tasks to the file in a structured format. + * + * @param tasks The list of tasks to be saved. + */ public void saveTasks(ArrayList tasks) { try (FileWriter fileWriter = new FileWriter(filePath); PrintWriter writer = new PrintWriter(fileWriter)) { @@ -44,10 +65,15 @@ public void saveTasks(ArrayList tasks) { } } + /** + * Converts a Task object into a storage-friendly string format. + * + * @param task The task to be formatted. + * @return A string representation of the task for storage. + */ public String formatTaskToStorage(Task task) { String taskInStorageFormat; - if (task instanceof ToDo) { taskInStorageFormat = "todo|" + task.getDoneStatus() + "|" + task.getDescription(); } @@ -68,6 +94,13 @@ else if (task instanceof Event eventTask) { return taskInStorageFormat; } + /** + * Parses a task from its stored string format. + * + * @param savedTask The string representation of the task from storage. + * @return The reconstructed Task object. + * @throws IllegalArgumentException If the format is invalid or unknown. + */ public Task formatTaskFromStorage(String savedTask) { String[] parts = savedTask.split("\\|"); // Split by "|" DateTimeFormatter dateTimeLoadFormat = DateTimeFormatter.ofPattern("dd/MM/yyyy"); diff --git a/src/main/java/Task.java b/src/main/java/Task.java index a60a85382..2350a8eb8 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,34 +1,71 @@ +/** + * Represents a task with a description and completion status. + */ public class Task { private final String description; protected boolean isDone; + /** + * Constructs a new task with the given description. + * By default, the task is not done. + * + * @param description The description of the task. + */ public Task(String description) { this.description = description; this.isDone = false; } + /** + * Constructs a new task with the given completion status and description. + * + * @param isDone The completion status of the task. + * @param description The description of the task. + */ public Task(boolean isDone, String description) { this.isDone = isDone; this.description = description; } + + /** + * Marks the task as done. + */ public void markAsDone() { isDone = true; } + + /** + * Marks the task as not done. + */ public void markAsNotDone() { isDone = false; } + /** + * Returns the status icon representing whether the task is done. + * + * @return "[X] " if the task is done, "[ ] " otherwise. + */ public String getStatusIcon() { return (isDone ? "[X] " : "[ ] "); } - public String getDoneStatus(){ + /** + * Returns the completion status of the task as a string. + * + * @return "done" if the task is completed, "not done" otherwise. + */ + public String getDoneStatus() { return (isDone ? "done" : "not done"); } - + /** + * Returns the description of the task. + * + * @return The task description. + */ public String getDescription() { return description; } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 129bcdf2d..632c18094 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,17 +1,38 @@ import Errors.InputExceptions; import java.util.ArrayList; +/** + * The TaskList class manages a collection of tasks. + * It provides methods to add, retrieve, remove, and get the size of the task list. + */ class TaskList { private final ArrayList tasks; + /** + * Constructs a TaskList with an existing list of tasks. + * + * @param tasks The list of tasks to manage. + */ public TaskList(ArrayList tasks) { this.tasks = tasks; } + /** + * Adds a new task to the list. + * + * @param task The task to be added. + */ public void addTask(Task task) { tasks.add(task); } + /** + * Retrieves a task at a specific index. + * + * @param index The index of the task. + * @return The task at the specified index. + * @throws InputExceptions If the index is out of bounds. + */ public Task getTask(int index) throws InputExceptions { if (index < 0 || index >= tasks.size()) { throw new InputExceptions.InvalidIndexException(); @@ -19,14 +40,30 @@ public Task getTask(int index) throws InputExceptions { return tasks.get(index); } + /** + * Returns the list of all tasks. + * + * @return An ArrayList of tasks. + */ public ArrayList getListOfTasks() { return tasks; } + /** + * Returns the number of tasks in the list. + * + * @return The size of the task list. + */ public int size() { return tasks.size(); } + /** + * Removes a task at a specified index. + * + * @param index The index of the task to be removed. + * @throws InputExceptions If the index is out of bounds. + */ public void removeTask(int index) throws InputExceptions { if (index < 0 || index >= tasks.size()) { throw new InputExceptions.InvalidIndexException(); diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java index a1448f147..dd3938f7f 100644 --- a/src/main/java/ToDo.java +++ b/src/main/java/ToDo.java @@ -1,13 +1,28 @@ +/** + * The ToDo class represents a simple task without a specific deadline or event period. + */ public class ToDo extends Task { - public ToDo(boolean isDone, String description) { - super(description); - this.isDone = isDone; - System.out.println("I have added this Todo: "); - System.out.println(this); - } - @Override - public String toString() { - return "[T]" + getStatusIcon() + getDescription(); - } + /** + * Constructs a ToDo task with a description and completion status. + * + * @param isDone The completion status of the task. + * @param description The description of the task. + */ + public ToDo(boolean isDone, String description) { + super(description); + this.isDone = isDone; + System.out.println("I have added this Todo: "); + System.out.println(this); + } + + /** + * Returns a string representation of the ToDo task. + * + * @return The formatted string representation of the task. + */ + @Override + public String toString() { + return "[T]" + getStatusIcon() + getDescription(); + } } diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 4c0786df0..4f55774d8 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,6 +1,11 @@ - +/** + * Handles user interface interactions by displaying messages and formatting output. + */ class UI { + /** + * Displays the welcome message along with ASCII art of BobChungus. + */ public void showWelcome() { System.out.println("____________________________________________________________"); ASCII_Art.printArt(); @@ -9,50 +14,86 @@ public void showWelcome() { System.out.println("____________________________________________________________"); } + /** + * Displays the goodbye message when exiting the program. + */ public void showGoodbye() { System.out.println("____________________________________________________________"); System.out.println(" Bye. Hope to see you again soon!"); System.out.println("____________________________________________________________"); } + /** + * Displays a header for the task list output. + */ public void showList() { System.out.println("____________________________________________________________"); System.out.println(" Here are the tasks in your list:"); } + /** + * Displays a message indicating a task has been deleted. + * + * @param deleteIndex The index of the task that was deleted. + */ public void deletedTask(int deleteIndex){ System.out.println("____________________________________________________________"); System.out.println("Okay, deleted Task " + (deleteIndex + 1)); System.out.println("____________________________________________________________"); } + /** + * Displays a message indicating a task has been marked as completed. + * + * @param markIndex The index of the task that was marked as done. + */ public void markedTask(int markIndex){ System.out.println("____________________________________________________________"); System.out.println("Okay, marked Task " + (markIndex + 1)); System.out.println("____________________________________________________________"); } + /** + * Displays a message indicating a task has been unmarked as completed. + * + * @param unmarkIndex The index of the task that was unmarked. + */ public void unmarkedTask(int unmarkIndex){ System.out.println("____________________________________________________________"); System.out.println("Okay, unmarked Task " + (unmarkIndex + 1)); System.out.println("____________________________________________________________"); } + /** + * Displays a message indicating that a search for tasks has begun. + */ public void printFindingTask(){ System.out.println("____________________________________________________________"); System.out.println("Here are the matching tasks in your list:"); } + /** + * Displays a message when no matching tasks are found during a search. + */ public void printNoTaskFound(){ printLine(); System.out.println("No task with matching keyword found"); } + /** + * Displays a found task from a search result. + * + * @param position The position of the task in the list. + * @param task The task object that was found. + */ public void printFoundTask(int position, Task task){ printLine(); System.out.println( position + "." + " " + task.toString() ); } + /** + * Prints a horizontal line for formatting output. + */ public void printLine() { System.out.println("____________________________________________________________"); } From 7f7c47d6d607cb761fd55adda867f5e1b0cc2fbe Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 14:26:25 +0800 Subject: [PATCH 20/31] A-UserGuide --- docs/README.md | 179 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 163 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 47b9f984f..35c032d3b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,30 +1,177 @@ -# Duke User Guide +# BobChungus - User Guide -// Update the title above to match the actual product name +## Overview -// Product screenshot goes here +BobChungus is a command-line based application intended as a Task Management System. It aims to help users manage their active tasks in the form of **todos**, **deadlines** and **events**. -// Product intro goes here +--- -## Adding deadlines +## Commands -// Describe the action and its outcome. +#### Notes about the Command Format -// Give examples of usage +
-Example: `keyword (optional arguments)` +- Words in UPPER_CASE are the parameters to be supplied by the user. + e.g. in TASK_DESCRIPTION is a parameter which can be replaced with the description of the task to be added +
-// A description of the expected outcome goes here +- Parameters must be in the specified order. + e.g. if the command specifies TASK_DESCRIPTION followed by TASK_DATE, + TASK_DATE followed by TASK_DESCRIPTION is NOT acceptable and will cause issues. +
-``` -expected output -``` +- Extraneous parameters for commands that do not take in parameters (such as list and bye) will cause errors. + e.g. if the command specifies bye 123, it will be create an error. +
-## Feature ABC +- If you are using a PDF version of this document, be careful when copying and pasting commands that span multiple lines as space characters surrounding line-breaks may be omitted when copied over to the application. -// Feature details +
+--- -## Feature XYZ +### List of Commnads -// Feature details \ No newline at end of file +--- + +### **Exiting the program:** `bye` + +**Description:** Exits the program. Saves all Tasks within `TaskList` before exitting. + +- **Use Case:** When the user is done, they can type `bye` to exit the program. +- **Format:** `bye` + +### **Display all Tasks:** `list` + +**Description:** Displays the list of tasks. + +- **Use Case:** When the user wants to view all tasks in their list. +- **Format:** `list` + +### **Create new `Todo` task:** `todo` + +**Description:** Adds a new to-do task. + +- **Use Case:** The user provides a description for the to-do task. +- **Arguments:** Task description (e.g., `todo Buy groceries`) +- **Format:** `todo TASK_DESCRIPTION` + +### **Create new `deadline` task:** `deadline` + +**Description:** Adds a new deadline task. + +- **Use Case:** The user provides a task description and a deadline date. +- **Arguments:** Task description followed by `/by` and the deadline date (e.g., `deadline Finish assignment /by 15-03-2025`). +- **Format:** `deadline TASK_DESCRIPTION /by DD-MM-YYYY` + +### **Create new `event` task:** `event` + +**Description:** Adds a new event task. + +- **Use Case:** The user provides an event description and start and end date. +- **Arguments:** Event description followed by `/from` (start date) and `/to` (end date) (e.g., `event Conference /from 20-03-2025 /to 22-03-2025`). +- **Format:** `event TASK_DESCRIPTION /from TASK_START_DATE(dd-MM-yyyy) /to TASK_END_DATE(dd-MM-yyyy)` + +--- + +
+ Note: Tasks are stored within the program 0-indexed, but are displayed and interacted with by users 1-indexed. +
+ +--- + +### **Delete a Task:** `delete` + +**Description:** Deletes a task by index. + +- **Use Case:** The user provides the index of the task to be deleted. +- **Arguments:** Task index (e.g., `delete 2` to delete the second task in the list). +- **Format:** `delete TASK_INDEX` + +### **Mark a task as complete:** `mark` + +**Description:** Marks a task as completed. + +- **Use Case:** The user provides the index of the task to mark as done. +- **Arguments:** Task index (e.g., `mark 3` to mark the third task as done). +- **Format:** `mark TASK_INDEX` + +### **Mark a task as not complete:** `unmark` + +**Description:** Marks a task as not completed. + +- **Use Case:** The user provides the index of the task to mark as not done. +- **Arguments:** Task index (e.g., `unmark 1` to unmark the first task). +- **Format:** `unmark TASK_INDEX` + +### **Find a task:** `find` + +**Description:** Finds tasks with a specific keyword in their description. + +- **Use Case:** The user provides a keyword to search for in the task descriptions. +- **Arguments:** Keyword to search for (e.g., `find meeting`). +- **Format:** `find TASK_DESCRIPTION` + +### **Saving your data** + +BobChungus' `TaskList` data is saved in the hard disk automatically after exiting with the `bye` command. +There is no need to save manually. + +### **Editing Saved data** + +BobChungus' `TaskList` Data is automatically saved as a `.txt` file at `[JAR file location]/data/userTasks.txt`. Advanced users are welcome to update data directly by editing that data file. + +
+ Caution: If your changes to the data file makes its format invalid, BobChungus will discard all data and start with an empty data file at the next run. Hence, it is recommended to take a backup of the file before editing it. + +Furthermore, certain edits can cause BobChungus to behave in unexpected ways (e.g., if a value entered is outside of the acceptable range). Therefore, edit the data file only if you are confident that you can update it correctly. + +
+ +--- + +## Command Summary + +| Command | Description | Arguments | Format | +| ---------- | ----------------------------------------- | ------------------------------------- | -------------------------------------------------- | +| `bye` | Exits the program | None | `bye` | +| `list` | Lists all tasks | None | `list` | +| `todo` | Adds a to-do task | Task description | `todo Buy groceries` | +| `deadline` | Adds a deadline task | Task description /by date | `deadline Submit report /by 18-03-2025` | +| `event` | Adds an event task | Event description /from date /to date | `event Conference /from 20-03-2025 /to 22-03-2025` | +| `delete` | Deletes a task by index | Task index | `delete 2` | +| `mark` | Marks a task as completed | Task index | `mark 3` | +| `unmark` | Marks a task as not completed | Task index | `unmark 1` | +| `find` | Finds tasks by keyword in the description | Search keyword | `find meeting` | + +--- + +## FAQs + +### 1. **What happens if I enter an invalid command?** + +- If you enter a command that is not recognized, the program will throw an exception and display an error message indicating that the command is invalid. + +### 2. **What if I forget to include the arguments for a command like `todo` or `deadline`?** + +- The program will throw an exception (`MissingTodoArgumentException`, `MissingDeadlineArgumentException`, etc.) and inform you that you are missing required arguments. + +### 3. **What format should the dates be in?** + +- All dates should be in the format `dd-MM-yyyy`, for Format, example `15-03-2025`. + +--- + +## Notes on Editing Data + +- The commands are case-insensitive, meaning you can type commands in any letter case (e.g., `todo`, `TODO`, `ToDo`). +- Ensure that the date format for commands like `deadline` and `event` is strictly followed (`dd-MM-yyyy`). +- You can modify the task list and storage handling by editing the `TaskList` and `Storage` classes. + +--- + +## Known Issues + +- **Date parsing errors**: If a date is not in the correct format (`dd-MM-yyyy`), a `DateTimeParseException` will be thrown. +- **Index errors**: Deleting or marking tasks by index requires the index to be valid; otherwise, an exception may occur if the user enters an invalid index. From ad1e2a16c3e117994ce51e0790367858fffca205 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 14:36:45 +0800 Subject: [PATCH 21/31] editted A-UserGuide --- README.md | 203 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 177 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index af0309a9e..35c032d3b 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,177 @@ -# 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. - -## Setting up in Intellij - -Prerequisites: JDK 17, update Intellij to the most recent version. - -1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) -1. Open the project into Intellij as follows: - 1. Click `Open`. - 1. Select the project directory, and click `OK`. - 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: - ``` - Hello from - ____ _ - | _ \ _ _| | _____ - | | | | | | | |/ / _ \ - | |_| | |_| | < __/ - |____/ \__,_|_|\_\___| - ``` - -**Warning:** Keep the `src\main\java` folder as the root folder for Java files (i.e., don't rename those folders or move Java files to another folder outside of this folder path), as this is the default location some tools (e.g., Gradle) expect to find Java files. +# BobChungus - User Guide + +## Overview + +BobChungus is a command-line based application intended as a Task Management System. It aims to help users manage their active tasks in the form of **todos**, **deadlines** and **events**. + +--- + +## Commands + +#### Notes about the Command Format + +
+ +- Words in UPPER_CASE are the parameters to be supplied by the user. + e.g. in TASK_DESCRIPTION is a parameter which can be replaced with the description of the task to be added +
+ +- Parameters must be in the specified order. + e.g. if the command specifies TASK_DESCRIPTION followed by TASK_DATE, + TASK_DATE followed by TASK_DESCRIPTION is NOT acceptable and will cause issues. +
+ +- Extraneous parameters for commands that do not take in parameters (such as list and bye) will cause errors. + e.g. if the command specifies bye 123, it will be create an error. +
+ +- If you are using a PDF version of this document, be careful when copying and pasting commands that span multiple lines as space characters surrounding line-breaks may be omitted when copied over to the application. + +
+ +--- + +### List of Commnads + +--- + +### **Exiting the program:** `bye` + +**Description:** Exits the program. Saves all Tasks within `TaskList` before exitting. + +- **Use Case:** When the user is done, they can type `bye` to exit the program. +- **Format:** `bye` + +### **Display all Tasks:** `list` + +**Description:** Displays the list of tasks. + +- **Use Case:** When the user wants to view all tasks in their list. +- **Format:** `list` + +### **Create new `Todo` task:** `todo` + +**Description:** Adds a new to-do task. + +- **Use Case:** The user provides a description for the to-do task. +- **Arguments:** Task description (e.g., `todo Buy groceries`) +- **Format:** `todo TASK_DESCRIPTION` + +### **Create new `deadline` task:** `deadline` + +**Description:** Adds a new deadline task. + +- **Use Case:** The user provides a task description and a deadline date. +- **Arguments:** Task description followed by `/by` and the deadline date (e.g., `deadline Finish assignment /by 15-03-2025`). +- **Format:** `deadline TASK_DESCRIPTION /by DD-MM-YYYY` + +### **Create new `event` task:** `event` + +**Description:** Adds a new event task. + +- **Use Case:** The user provides an event description and start and end date. +- **Arguments:** Event description followed by `/from` (start date) and `/to` (end date) (e.g., `event Conference /from 20-03-2025 /to 22-03-2025`). +- **Format:** `event TASK_DESCRIPTION /from TASK_START_DATE(dd-MM-yyyy) /to TASK_END_DATE(dd-MM-yyyy)` + +--- + +
+ Note: Tasks are stored within the program 0-indexed, but are displayed and interacted with by users 1-indexed. +
+ +--- + +### **Delete a Task:** `delete` + +**Description:** Deletes a task by index. + +- **Use Case:** The user provides the index of the task to be deleted. +- **Arguments:** Task index (e.g., `delete 2` to delete the second task in the list). +- **Format:** `delete TASK_INDEX` + +### **Mark a task as complete:** `mark` + +**Description:** Marks a task as completed. + +- **Use Case:** The user provides the index of the task to mark as done. +- **Arguments:** Task index (e.g., `mark 3` to mark the third task as done). +- **Format:** `mark TASK_INDEX` + +### **Mark a task as not complete:** `unmark` + +**Description:** Marks a task as not completed. + +- **Use Case:** The user provides the index of the task to mark as not done. +- **Arguments:** Task index (e.g., `unmark 1` to unmark the first task). +- **Format:** `unmark TASK_INDEX` + +### **Find a task:** `find` + +**Description:** Finds tasks with a specific keyword in their description. + +- **Use Case:** The user provides a keyword to search for in the task descriptions. +- **Arguments:** Keyword to search for (e.g., `find meeting`). +- **Format:** `find TASK_DESCRIPTION` + +### **Saving your data** + +BobChungus' `TaskList` data is saved in the hard disk automatically after exiting with the `bye` command. +There is no need to save manually. + +### **Editing Saved data** + +BobChungus' `TaskList` Data is automatically saved as a `.txt` file at `[JAR file location]/data/userTasks.txt`. Advanced users are welcome to update data directly by editing that data file. + +
+ Caution: If your changes to the data file makes its format invalid, BobChungus will discard all data and start with an empty data file at the next run. Hence, it is recommended to take a backup of the file before editing it. + +Furthermore, certain edits can cause BobChungus to behave in unexpected ways (e.g., if a value entered is outside of the acceptable range). Therefore, edit the data file only if you are confident that you can update it correctly. + +
+ +--- + +## Command Summary + +| Command | Description | Arguments | Format | +| ---------- | ----------------------------------------- | ------------------------------------- | -------------------------------------------------- | +| `bye` | Exits the program | None | `bye` | +| `list` | Lists all tasks | None | `list` | +| `todo` | Adds a to-do task | Task description | `todo Buy groceries` | +| `deadline` | Adds a deadline task | Task description /by date | `deadline Submit report /by 18-03-2025` | +| `event` | Adds an event task | Event description /from date /to date | `event Conference /from 20-03-2025 /to 22-03-2025` | +| `delete` | Deletes a task by index | Task index | `delete 2` | +| `mark` | Marks a task as completed | Task index | `mark 3` | +| `unmark` | Marks a task as not completed | Task index | `unmark 1` | +| `find` | Finds tasks by keyword in the description | Search keyword | `find meeting` | + +--- + +## FAQs + +### 1. **What happens if I enter an invalid command?** + +- If you enter a command that is not recognized, the program will throw an exception and display an error message indicating that the command is invalid. + +### 2. **What if I forget to include the arguments for a command like `todo` or `deadline`?** + +- The program will throw an exception (`MissingTodoArgumentException`, `MissingDeadlineArgumentException`, etc.) and inform you that you are missing required arguments. + +### 3. **What format should the dates be in?** + +- All dates should be in the format `dd-MM-yyyy`, for Format, example `15-03-2025`. + +--- + +## Notes on Editing Data + +- The commands are case-insensitive, meaning you can type commands in any letter case (e.g., `todo`, `TODO`, `ToDo`). +- Ensure that the date format for commands like `deadline` and `event` is strictly followed (`dd-MM-yyyy`). +- You can modify the task list and storage handling by editing the `TaskList` and `Storage` classes. + +--- + +## Known Issues + +- **Date parsing errors**: If a date is not in the correct format (`dd-MM-yyyy`), a `DateTimeParseException` will be thrown. +- **Index errors**: Deleting or marking tasks by index requires the index to be valid; otherwise, an exception may occur if the user enters an invalid index. From 61305365c97685fa9a1af767e5eee39fc36a816f Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 14:48:41 +0800 Subject: [PATCH 22/31] added minor bug fixing, file creation and error responses --- src/main/java/Errors/InputExceptions.java | 6 +++--- src/main/java/Storage.java | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/Errors/InputExceptions.java b/src/main/java/Errors/InputExceptions.java index 1d5f64045..c4dba1fea 100644 --- a/src/main/java/Errors/InputExceptions.java +++ b/src/main/java/Errors/InputExceptions.java @@ -8,21 +8,21 @@ public InputExceptions(String message) { public static class MissingTodoArgumentException extends InputExceptions { public MissingTodoArgumentException(String command) { super(command + " must have arguments." + "\n" + - "Please use: \"todo\" \"task\" instead"); + "Please use: \"todo\" \"TASK_DESCRIPTION\" instead"); } } public static class MissingDeadlineArgumentException extends InputExceptions { public MissingDeadlineArgumentException(String command) { super(command + " must have arguments." + "\n" + - "Please use: \"deadline\" \"task\" /by \"deadline\" instead"); + "Please use: \"deadline\" \"TASK_DESCRIPTION\" /by \"TASK_DEADLINE\" instead"); } } public static class MissingEventArgumentException extends InputExceptions { public MissingEventArgumentException(String command) { super(command + " must have arguments." + "\n" + - "Please use: \"event\" \"task\" /from \"eventfrom\" /to \"eventto\" instead"); + "Please use: \"event\" \"TASK_DESCRIPTION\" /from \"TASK_START_DATE\" /to \"TASK_END_DATE\" instead"); } } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index b5845571e..fcdaecd3c 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -32,7 +32,12 @@ public ArrayList loadTasks() throws FileNotFoundException { ArrayList tasks = new ArrayList<>(); File file = new File(filePath); if (!file.exists()) { - System.out.println("File does not exist, starting with an empty list."); + try { + file.createNewFile(); + System.out.println("File not found. A new file has been created."); + } catch (IOException e) { + System.err.println("Error creating new file: " + e.getMessage()); + } return tasks; } Scanner scanner = new Scanner(file); From d0d692dfdfef3a50df4d4c3c6dd278da799faae9 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 14:55:06 +0800 Subject: [PATCH 23/31] added bug fix for missing data folder --- src/main/java/Storage.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index fcdaecd3c..374c75ed2 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -31,14 +31,20 @@ public Storage(String filePath) { public ArrayList loadTasks() throws FileNotFoundException { ArrayList tasks = new ArrayList<>(); File file = new File(filePath); + File parentDir = file.getParentFile(); + if (!file.exists()) { try { + if (parentDir != null && !parentDir.exists()) { + parentDir.mkdirs(); + } file.createNewFile(); - System.out.println("File not found. A new file has been created."); + System.out.println("File not found. A new file 'userData.txt' has been created in 'data' folder."); } catch (IOException e) { System.err.println("Error creating new file: " + e.getMessage()); } return tasks; + return tasks; } Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { From 34dc388948664c78ad86d563db36a98837bafff5 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 14:58:51 +0800 Subject: [PATCH 24/31] ascii art bug --- src/main/java/ASCII_Art.java | 10 +++++++++- src/main/java/Storage.java | 1 - 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/ASCII_Art.java b/src/main/java/ASCII_Art.java index f020ca728..6dd16c337 100644 --- a/src/main/java/ASCII_Art.java +++ b/src/main/java/ASCII_Art.java @@ -1,3 +1,6 @@ +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; + public class ASCII_Art { public static String art = """ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣧⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ @@ -30,7 +33,12 @@ public class ASCII_Art { public static void printArt() { - System.out.println(art); + try { + PrintStream out = new PrintStream(System.out, true, StandardCharsets.UTF_8); + out.println(art); + } catch (Exception e) { + System.err.println("Error printing ASCII Art: " + e.getMessage()); + } } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 374c75ed2..1f2615803 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -44,7 +44,6 @@ public ArrayList loadTasks() throws FileNotFoundException { System.err.println("Error creating new file: " + e.getMessage()); } return tasks; - return tasks; } Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { From 48bb30c6b381c83db68035c9c9708a3f3a5cf935 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 15:08:53 +0800 Subject: [PATCH 25/31] ascii art bug --- src/main/java/ASCII_Art.java | 39 ++++++++++-------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/src/main/java/ASCII_Art.java b/src/main/java/ASCII_Art.java index 6dd16c337..2b00b42f9 100644 --- a/src/main/java/ASCII_Art.java +++ b/src/main/java/ASCII_Art.java @@ -3,39 +3,22 @@ public class ASCII_Art { public static String art = """ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣧⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣧⠀⠀⠀⢰⡿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡟⡆⠀⠀⣿⡇⢻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠀⣿⠀⢰⣿⡇⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡄⢸⠀⢸⣿⡇⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡇⢸⡄⠸⣿⡇⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⢸⡅⠀⣿⢠⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣥⣾⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⡿⡿⣿⣿⡿⡅⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠉⠀⠉⡙⢔⠛⣟⢋⠦⢵⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣄⠀⠀⠁⣿⣯⡥⠃⠀⢳⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡇⠀⠀⠀⠐⠠⠊⢀⠀⢸⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⡿⠀⠀⠀⠀⠀⠈⠁⠀⠀⠘⣿⣄⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⣠⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣷⡀⠀⠀⠀ -⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣧⠀⠀ -⠀⠀⠀⡜⣭⠤⢍⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢛⢭⣗⠀ -⠀⠀⠀⠁⠈⠀⠀⣀⠝⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠠⠀⠀⠰⡅ -⠀⠀⠀⢀⠀⠀⡀⠡⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠔⠠⡕⠀ -⠀⠀⠀⠀⣿⣷⣶⠒⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠀⠀⠀⠀ -⠀⠀⠀⠀⠘⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠈⢿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠊⠉⢆⠀⠀⠀⠀ -⠀⢀⠤⠀⠀⢤⣤⣽⣿⣿⣦⣀⢀⡠⢤⡤⠄⠀⠒⠀⠁⠀⠀⠀⢘⠔⠀⠀⠀⠀ -⠀⠀⠀⡐⠈⠁⠈⠛⣛⠿⠟⠑⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠉⠑⠒⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -"""; + ____ _ _____ _ \s + | _ \\ | | / ____| | \s + | |_) | ___ | |__ | | | |__ _ _ _ __ __ _ _ _ ___\s + | _ < / _ \\| '_ \\ | | | '_ \\| | | | '_ \\ / _` | | | / __| + | |_) | (_) | |_) | | |____| | | | |_| | | | | (_| | |_| \\__ \\ + |____/ \\___/|_.__/ \\_____|_| |_|\\__,_|_| |_|\\__, |\\__,_|___/ + __/ | \s + |___/ \s⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + """; + public static void printArt() { try { - PrintStream out = new PrintStream(System.out, true, StandardCharsets.UTF_8); - out.println(art); + System.out.write(art.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { System.err.println("Error printing ASCII Art: " + e.getMessage()); } From 2161a47492f0c14dbb82f2a68c914374459064f8 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 15:12:22 +0800 Subject: [PATCH 26/31] ascii art bug --- src/main/java/ASCII_Art.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/ASCII_Art.java b/src/main/java/ASCII_Art.java index 2b00b42f9..ea7836739 100644 --- a/src/main/java/ASCII_Art.java +++ b/src/main/java/ASCII_Art.java @@ -3,22 +3,21 @@ public class ASCII_Art { public static String art = """ - ____ _ _____ _ \s - | _ \\ | | / ____| | \s - | |_) | ___ | |__ | | | |__ _ _ _ __ __ _ _ _ ___\s + ____ _ _____ _ + | _ \\ | | / ____| | + | |_) | ___ | |__ | | | |__ _ _ _ __ __ _ _ _ ___ | _ < / _ \\| '_ \\ | | | '_ \\| | | | '_ \\ / _` | | | / __| | |_) | (_) | |_) | | |____| | | | |_| | | | | (_| | |_| \\__ \\ |____/ \\___/|_.__/ \\_____|_| |_|\\__,_|_| |_|\\__, |\\__,_|___/ - __/ | \s - |___/ \s⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - """; + __/ | + |___/"""; public static void printArt() { try { - System.out.write(art.getBytes(StandardCharsets.UTF_8)); + System.out.println(art); } catch (Exception e) { System.err.println("Error printing ASCII Art: " + e.getMessage()); } From 3d376b21c5dae778afe5a8ef2f2d4d4ad5c69962 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 15:33:34 +0800 Subject: [PATCH 27/31] edittde user guide --- docs/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 35c032d3b..3317c29a4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,23 +8,28 @@ BobChungus is a command-line based application intended as a Task Management Sys ## Commands -#### Notes about the Command Format +
+ Notes about the Command Format + - Words in UPPER_CASE are the parameters to be supplied by the user. e.g. in TASK_DESCRIPTION is a parameter which can be replaced with the description of the task to be added
+ - Parameters must be in the specified order. e.g. if the command specifies TASK_DESCRIPTION followed by TASK_DATE, TASK_DATE followed by TASK_DESCRIPTION is NOT acceptable and will cause issues.
+ - Extraneous parameters for commands that do not take in parameters (such as list and bye) will cause errors. e.g. if the command specifies bye 123, it will be create an error.
+ - If you are using a PDF version of this document, be careful when copying and pasting commands that span multiple lines as space characters surrounding line-breaks may be omitted when copied over to the application.
From 04640b13e78799bf5abe2c064a216b2ae9d3a992 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 15:37:31 +0800 Subject: [PATCH 28/31] testing userguide --- docs/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 3317c29a4..436b6cac8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,18 +16,18 @@ BobChungus is a command-line based application intended as a Task Management Sys - Words in UPPER_CASE are the parameters to be supplied by the user. e.g. in TASK_DESCRIPTION is a parameter which can be replaced with the description of the task to be added -
+
- Parameters must be in the specified order. e.g. if the command specifies TASK_DESCRIPTION followed by TASK_DATE, TASK_DATE followed by TASK_DESCRIPTION is NOT acceptable and will cause issues. -
+
- Extraneous parameters for commands that do not take in parameters (such as list and bye) will cause errors. e.g. if the command specifies bye 123, it will be create an error. -
+
- If you are using a PDF version of this document, be careful when copying and pasting commands that span multiple lines as space characters surrounding line-breaks may be omitted when copied over to the application. @@ -36,7 +36,7 @@ BobChungus is a command-line based application intended as a Task Management Sys --- -### List of Commnads +### List of Commands --- From 649909e52a5ba72557d6899b7a63a356335a88a8 Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 15:42:01 +0800 Subject: [PATCH 29/31] testing userguide --- docs/README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index 436b6cac8..72ce22926 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,24 +13,29 @@ BobChungus is a command-line based application intended as a Task Management Sys
Notes about the Command Format +
- Words in UPPER_CASE are the parameters to be supplied by the user. e.g. in TASK_DESCRIPTION is a parameter which can be replaced with the description of the task to be added -
+ +
+
- Parameters must be in the specified order. e.g. if the command specifies TASK_DESCRIPTION followed by TASK_DATE, TASK_DATE followed by TASK_DESCRIPTION is NOT acceptable and will cause issues. -
- +
+
- Extraneous parameters for commands that do not take in parameters (such as list and bye) will cause errors. e.g. if the command specifies bye 123, it will be create an error. -
- +
+
- If you are using a PDF version of this document, be careful when copying and pasting commands that span multiple lines as space characters surrounding line-breaks may be omitted when copied over to the application. +
+
From e417e4b6c01406979fc651db6f5b6c8366b1d78b Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Wed, 12 Mar 2025 15:43:32 +0800 Subject: [PATCH 30/31] testing userguide --- docs/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 72ce22926..f24d39545 100644 --- a/docs/README.md +++ b/docs/README.md @@ -14,13 +14,12 @@ BobChungus is a command-line based application intended as a Task Management Sys Notes about the Command Format
+
- Words in UPPER_CASE are the parameters to be supplied by the user. e.g. in TASK_DESCRIPTION is a parameter which can be replaced with the description of the task to be added - -
-
- +
+
- Parameters must be in the specified order. e.g. if the command specifies TASK_DESCRIPTION followed by TASK_DATE, From 552f814a79799436f7fe7d12d3f2fef0736eab8d Mon Sep 17 00:00:00 2001 From: Jonathan2745 Date: Thu, 13 Mar 2025 10:23:37 +0800 Subject: [PATCH 31/31] minor changes to JavaDoc --- docs/README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index f24d39545..22c65ccb8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -142,17 +142,17 @@ Furthermore, certain edits can cause BobChungus to behave in unexpected ways (e. ## Command Summary -| Command | Description | Arguments | Format | -| ---------- | ----------------------------------------- | ------------------------------------- | -------------------------------------------------- | -| `bye` | Exits the program | None | `bye` | -| `list` | Lists all tasks | None | `list` | -| `todo` | Adds a to-do task | Task description | `todo Buy groceries` | -| `deadline` | Adds a deadline task | Task description /by date | `deadline Submit report /by 18-03-2025` | -| `event` | Adds an event task | Event description /from date /to date | `event Conference /from 20-03-2025 /to 22-03-2025` | -| `delete` | Deletes a task by index | Task index | `delete 2` | -| `mark` | Marks a task as completed | Task index | `mark 3` | -| `unmark` | Marks a task as not completed | Task index | `unmark 1` | -| `find` | Finds tasks by keyword in the description | Search keyword | `find meeting` | +| Command | Description | Arguments | Format | +| ---------- | ----------------------------------------- |---------------------------------------------| -------------------------------------------------- | +| `bye` | Exits the program | None | `bye` | +| `list` | Lists all tasks | None | `list` | +| `todo` | Adds a to-do task | TASK_DESCRIPTION | `todo Buy groceries` | +| `deadline` | Adds a deadline task | TASK_DESCRIPTION /by DD-MM-YYYY | `deadline Submit report /by 18-03-2025` | +| `event` | Adds an event task | TASK_DESCRIPTION /from DD-MM-YYYY /to DD-MM-YYYY | `event Conference /from 20-03-2025 /to 22-03-2025` | +| `delete` | Deletes a task by index | TASK_INDEX (1-indexed) | `delete 2` | +| `mark` | Marks a task as completed | TASK_INDEX (1-indexed) | `mark 3` | +| `unmark` | Marks a task as not completed | TASK_INDEX (1-indexed) | `unmark 1` | +| `find` | Finds tasks by keyword in the description | SEARCH_KEYWORD | `find meeting` | --- @@ -160,7 +160,7 @@ Furthermore, certain edits can cause BobChungus to behave in unexpected ways (e. ### 1. **What happens if I enter an invalid command?** -- If you enter a command that is not recognized, the program will throw an exception and display an error message indicating that the command is invalid. +- If you enter a command that is not recognized, the program will throw an exception and display an error message indicating that the command is invalid. You may then follow the instructions in the error code for the correct formatting of inputs. ### 2. **What if I forget to include the arguments for a command like `todo` or `deadline`?**