From cd60db60bf2f6900e3d1f1a79803f4f8efd2d086 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Thu, 29 Aug 2024 16:54:40 +0800 Subject: [PATCH 01/21] Level 0: Rename, Greet, Exit --- src/main/java/Duke.java | 10 ---------- src/main/java/Poirot.java | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 src/main/java/Duke.java create mode 100644 src/main/java/Poirot.java diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java new file mode 100644 index 000000000..eab2a7872 --- /dev/null +++ b/src/main/java/Poirot.java @@ -0,0 +1,10 @@ +public class Poirot { + public static void main(String[] args) { + System.out.println("____________________________________________________________\n"); + System.out.println("Hello! I'm POIROT\n"); + System.out.println("What can I do for you?"); + System.out.println("____________________________________________________________\n"); + System.out.println("Bye. Hope to see you again soon!"); + System.out.println("____________________________________________________________\n"); + } +} \ No newline at end of file From 4814b4e73e2aee3c2b0e0386ec1514aba5ff33a8 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Thu, 29 Aug 2024 17:03:37 +0800 Subject: [PATCH 02/21] Level 1: Echo --- src/main/java/Poirot.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index eab2a7872..b4c53b4a4 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -1,9 +1,29 @@ +import java.util.Scanner; + public class Poirot { + + public static void echo(String msg) { + System.out.println("____________________________________________________________\n"); + System.out.println(msg); + System.out.println("____________________________________________________________\n"); + } + public static void main(String[] args) { System.out.println("____________________________________________________________\n"); System.out.println("Hello! I'm POIROT\n"); System.out.println("What can I do for you?"); System.out.println("____________________________________________________________\n"); + boolean working = true; + Scanner scan = new Scanner(System.in); + while (working) { + String input = scan.nextLine(); + if (input.equalsIgnoreCase("bye")) { + working = false; + } else { + echo(input); + } + } + System.out.println("____________________________________________________________\n"); System.out.println("Bye. Hope to see you again soon!"); System.out.println("____________________________________________________________\n"); } From 4f308d27a8996186fa0cfa7b58a21bc757606bda Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Thu, 29 Aug 2024 17:12:51 +0800 Subject: [PATCH 03/21] Level 2. Add, List --- src/main/java/Poirot.java | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index b4c53b4a4..bcc80a746 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -1,6 +1,8 @@ import java.util.Scanner; public class Poirot { + private static String[] list_actions = new String[100]; + private static int last_index = 0; public static void echo(String msg) { System.out.println("____________________________________________________________\n"); @@ -8,6 +10,27 @@ public static void echo(String msg) { System.out.println("____________________________________________________________\n"); } + public static void print(String[] list) { + if (last_index == 0) { + System.out.println("__________________________________________________________\n"); + System.out.println("No actions available"); + } else { + System.out.println("___________________________________________________________\n"); + for (int i = 0; i < last_index; i++) { + System.out.println(i + 1 + "." + list_actions[i] + " "); + } + } + System.out.println("___________________________________________________________\n"); + } + + public static void add(String action) { + list_actions[last_index] = action; + last_index++; + System.out.println("___________________________________________________________\n"); + System.out.println("added: " + action); + System.out.println("___________________________________________________________\n"); + } + public static void main(String[] args) { System.out.println("____________________________________________________________\n"); System.out.println("Hello! I'm POIROT\n"); @@ -17,10 +40,15 @@ public static void main(String[] args) { Scanner scan = new Scanner(System.in); while (working) { String input = scan.nextLine(); - if (input.equalsIgnoreCase("bye")) { - working = false; - } else { - echo(input); + switch (input) { + case "list": + print(list_actions); + break; + case "bye": + working = false; + break; + default: + add(input); } } System.out.println("____________________________________________________________\n"); From 6f3e69b99db38dd07706c111a9fe89ae0c38da8d Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Thu, 29 Aug 2024 17:38:47 +0800 Subject: [PATCH 04/21] Level 3. Mark as Done --- src/main/java/Poirot.java | 53 ++++++++++++++++++++++++++++++--------- src/main/java/Task.java | 21 ++++++++++++++++ 2 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 src/main/java/Task.java diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index bcc80a746..d79e4f15f 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -1,7 +1,7 @@ import java.util.Scanner; public class Poirot { - private static String[] list_actions = new String[100]; + private static Task[] list_actions = new Task[100]; private static int last_index = 0; public static void echo(String msg) { @@ -10,25 +10,25 @@ public static void echo(String msg) { System.out.println("____________________________________________________________\n"); } - public static void print(String[] list) { + public static void print(Task[] list) { if (last_index == 0) { - System.out.println("__________________________________________________________\n"); + System.out.println("____________________________________________________________\n"); System.out.println("No actions available"); } else { - System.out.println("___________________________________________________________\n"); + System.out.println("____________________________________________________________\n"); for (int i = 0; i < last_index; i++) { - System.out.println(i + 1 + "." + list_actions[i] + " "); + System.out.println((i + 1) + ".[" + list_actions[i].getStatusIcon() + "]" + list_actions[i].getDescription()); } } - System.out.println("___________________________________________________________\n"); + System.out.println("____________________________________________________________\n"); } - public static void add(String action) { + public static void add(Task action) { list_actions[last_index] = action; last_index++; - System.out.println("___________________________________________________________\n"); - System.out.println("added: " + action); - System.out.println("___________________________________________________________\n"); + System.out.println("____________________________________________________________\n"); + System.out.println("added: " + action.getDescription()); + System.out.println("____________________________________________________________\n"); } public static void main(String[] args) { @@ -40,15 +40,44 @@ public static void main(String[] args) { Scanner scan = new Scanner(System.in); while (working) { String input = scan.nextLine(); - switch (input) { + String[] list_input = input.split(" "); + switch (list_input[0]) { case "list": print(list_actions); break; case "bye": working = false; break; + case "mark": + int x = Integer.parseInt(list_input[1]) - 1; + list_actions[x].setDone(true); + System.out.println("____________________________________________________________\n"); + System.out.println("Nice! I've marked this task as done:\n"); + System.out.print("[" + list_actions[x].getStatusIcon() + "] "); + System.out.println(list_actions[x].getDescription()); + System.out.println("____________________________________________________________\n"); + break; + case "unmark": + int y = Integer.parseInt(list_input[1]) - 1; + list_actions[y].setDone(false); + System.out.println("____________________________________________________________\n"); + System.out.println("OK, I've marked this task as not done yet:\n"); + System.out.print("[" + list_actions[y].getStatusIcon() + "] "); + System.out.println(list_actions[y].getDescription()); + System.out.println("____________________________________________________________\n"); + break; default: - add(input); + String clearInput = input.trim(); + if(clearInput.isEmpty()){ + System.out.println("____________________________________________________________\n"); + System.out.println("Invalid task"); + System.out.println("____________________________________________________________\n"); + } + else { + Task newTask = new Task(clearInput); + add(newTask); + } + break; } } System.out.println("____________________________________________________________\n"); diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..e3fb1faef --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,21 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + public String getDescription() { + return description; + } + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + public void setDone(boolean isDone) { + this.isDone = isDone; + } + public void markAsDone(){ + this.isDone = true; + } +} From 88772472d20013d4f3cb765bdcc8ca9ace4cc948 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Wed, 4 Sep 2024 21:52:53 +0800 Subject: [PATCH 05/21] Level 4. ToDos, Events, Deadlines --- src/main/java/Deadline.java | 13 ++++++ src/main/java/Event.java | 15 +++++++ src/main/java/Poirot.java | 83 ++++++++++++++++++++----------------- src/main/java/Task.java | 6 +-- src/main/java/Todo.java | 10 +++++ 5 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 src/main/java/Deadline.java create mode 100644 src/main/java/Event.java create mode 100644 src/main/java/Todo.java diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..2a9bd844f --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,13 @@ +public class Deadline extends Task{ + private String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D][" + getStatusIcon() + "] " + description + " (by: " + by + ")"; + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..dbe8f8467 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task { + private String from; + private String to; + + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + @Override + public String toString() { + return "[E][" + getStatusIcon() + "] " + description + " (from: " + from + " to: " + to + ")"; + } +} diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index d79e4f15f..1995d2165 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -1,41 +1,44 @@ import java.util.Scanner; public class Poirot { - private static Task[] list_actions = new Task[100]; + public static final String LINE = "____________________________________________________________\n"; + private static Task[] tasks = new Task[100]; private static int last_index = 0; public static void echo(String msg) { - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); System.out.println(msg); - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); } - public static void print(Task[] list) { + public static void print(Task[] tasks) { if (last_index == 0) { - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); System.out.println("No actions available"); } else { - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); for (int i = 0; i < last_index; i++) { - System.out.println((i + 1) + ".[" + list_actions[i].getStatusIcon() + "]" + list_actions[i].getDescription()); + System.out.println((i + 1) + "." + tasks[i]); } } - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); } - public static void add(Task action) { - list_actions[last_index] = action; + public static void add(Task task) { + tasks[last_index] = task; last_index++; - System.out.println("____________________________________________________________\n"); - System.out.println("added: " + action.getDescription()); - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); + System.out.println("Got it. I've added this task:"); + System.out.println(" " + task); + System.out.println("Now you have " + last_index + " tasks in the list."); + System.out.println(LINE); } public static void main(String[] args) { - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); System.out.println("Hello! I'm POIROT\n"); System.out.println("What can I do for you?"); - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); boolean working = true; Scanner scan = new Scanner(System.in); while (working) { @@ -43,45 +46,49 @@ public static void main(String[] args) { String[] list_input = input.split(" "); switch (list_input[0]) { case "list": - print(list_actions); + print(tasks); break; case "bye": working = false; break; case "mark": int x = Integer.parseInt(list_input[1]) - 1; - list_actions[x].setDone(true); - System.out.println("____________________________________________________________\n"); + tasks[x].setDone(true); + System.out.println(LINE); System.out.println("Nice! I've marked this task as done:\n"); - System.out.print("[" + list_actions[x].getStatusIcon() + "] "); - System.out.println(list_actions[x].getDescription()); - System.out.println("____________________________________________________________\n"); + System.out.print("[" + tasks[x].getStatusIcon() + "] "); + System.out.println(tasks[x].getDescription()); + System.out.println(LINE); break; case "unmark": int y = Integer.parseInt(list_input[1]) - 1; - list_actions[y].setDone(false); - System.out.println("____________________________________________________________\n"); + tasks[y].setDone(false); + System.out.println(LINE); System.out.println("OK, I've marked this task as not done yet:\n"); - System.out.print("[" + list_actions[y].getStatusIcon() + "] "); - System.out.println(list_actions[y].getDescription()); - System.out.println("____________________________________________________________\n"); + System.out.print("[" + tasks[y].getStatusIcon() + "] "); + System.out.println(tasks[y].getDescription()); + System.out.println(LINE); + break; + case "todo": + String todoDescription = input.substring(5).trim(); + add(new Todo(todoDescription)); + break; + case "deadline": + String[] deadlineParts = input.substring(9).split(" /by "); + add(new Deadline(deadlineParts[0], deadlineParts[1])); + break; + case "event": + String[] eventParts = input.substring(6).split(" /from "); + String[] timeParts = eventParts[1].split(" /to "); + add(new Event(eventParts[0], timeParts[0], timeParts[1])); break; default: - String clearInput = input.trim(); - if(clearInput.isEmpty()){ - System.out.println("____________________________________________________________\n"); - System.out.println("Invalid task"); - System.out.println("____________________________________________________________\n"); - } - else { - Task newTask = new Task(clearInput); - add(newTask); - } + echo("Invalid command"); break; } } - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); System.out.println("Bye. Hope to see you again soon!"); - System.out.println("____________________________________________________________\n"); + System.out.println(LINE); } } \ No newline at end of file diff --git a/src/main/java/Task.java b/src/main/java/Task.java index e3fb1faef..e68e9d5a4 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -1,4 +1,4 @@ -public class Task { +abstract class Task { protected String description; protected boolean isDone; @@ -15,7 +15,5 @@ public String getStatusIcon() { public void setDone(boolean isDone) { this.isDone = isDone; } - public void markAsDone(){ - this.isDone = true; - } + public abstract String toString(); } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..7b9465a86 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,10 @@ +public class Todo extends Task{ + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T][" + getStatusIcon() + "] " + description; + } +} From 92fffd2c4028a4273fc73529cb83020704220d40 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Tue, 10 Sep 2024 22:09:57 +0800 Subject: [PATCH 06/21] Try testing --- text-ui-test/EXPECTED.TXT | 47 ++++++++++++++++++++++++++++++++++----- text-ui-test/input.txt | 5 +++++ text-ui-test/runtest.bat | 6 ++--- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..b4f2ce97e 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,42 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| +____________________________________________________________ +Hello! I'm POIROT + +What can I do for you? +____________________________________________________________ + +todo borrow book +____________________________________________________________ + +Got it. I've added this task: + [T][ ] borrow book +Now you have 1 tasks in the list. +____________________________________________________________ + +list +____________________________________________________________ + +1.[T][ ] borrow book +____________________________________________________________ + +deadline return book /by Sunday +____________________________________________________________ + +Got it. I've added this task: + [D][ ] return book (by: Sunday) +Now you have 2 tasks in the list. +____________________________________________________________ + +event project meeting /from Mon 2pm /to 4pm +____________________________________________________________ + +Got it. I've added this task: + [E][ ] project meeting (from: Mon 2pm to: 4pm) +Now you have 3 tasks in the list. +____________________________________________________________ + +bye +____________________________________________________________ + +Bye. Hope to see you again soon! +____________________________________________________________ \ No newline at end of file diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..30b2c284e 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,5 @@ +todo borrow book +list +deadline return book /by Sunday +event project meeting /from Mon 2pm /to 4pm +bye \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..57b286e0b 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -7,7 +7,7 @@ REM delete output from previous run if exist ACTUAL.TXT del ACTUAL.TXT REM compile the code into the bin folder -javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java +javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\Poirot.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Poirot < input.txt > ACTUAL.TXT REM compare the output to the expected output -FC ACTUAL.TXT EXPECTED.TXT +FC ACTUAL.TXT EXPECTED.TXT \ No newline at end of file From bf62b4dbac9c7dfbdb9c9bf1839a01b11c092d88 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Tue, 10 Sep 2024 22:12:43 +0800 Subject: [PATCH 07/21] Level 5. Handle Errors --- src/main/java/Poirot.java | 108 ++++++++++++++++++----------- src/main/java/PoirotException.java | 5 ++ 2 files changed, 72 insertions(+), 41 deletions(-) create mode 100644 src/main/java/PoirotException.java diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index 1995d2165..ab253c615 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -44,51 +44,77 @@ public static void main(String[] args) { while (working) { String input = scan.nextLine(); String[] list_input = input.split(" "); - switch (list_input[0]) { - case "list": - print(tasks); - break; - case "bye": - working = false; - break; - case "mark": - int x = Integer.parseInt(list_input[1]) - 1; - tasks[x].setDone(true); - System.out.println(LINE); - System.out.println("Nice! I've marked this task as done:\n"); - System.out.print("[" + tasks[x].getStatusIcon() + "] "); - System.out.println(tasks[x].getDescription()); - System.out.println(LINE); - break; - case "unmark": - int y = Integer.parseInt(list_input[1]) - 1; - tasks[y].setDone(false); - System.out.println(LINE); - System.out.println("OK, I've marked this task as not done yet:\n"); - System.out.print("[" + tasks[y].getStatusIcon() + "] "); - System.out.println(tasks[y].getDescription()); - System.out.println(LINE); - break; - case "todo": - String todoDescription = input.substring(5).trim(); - add(new Todo(todoDescription)); - break; - case "deadline": - String[] deadlineParts = input.substring(9).split(" /by "); - add(new Deadline(deadlineParts[0], deadlineParts[1])); - break; - case "event": - String[] eventParts = input.substring(6).split(" /from "); - String[] timeParts = eventParts[1].split(" /to "); - add(new Event(eventParts[0], timeParts[0], timeParts[1])); - break; - default: - echo("Invalid command"); - break; + try { + switch (list_input[0]) { + case "list": + print(tasks); + break; + case "bye": + working = false; + break; + case "mark": + validateTaskNumber(list_input); + int x = Integer.parseInt(list_input[1]) - 1; + tasks[x].setDone(true); + System.out.println(LINE); + System.out.println("Nice! I've marked this task as done:\n"); + System.out.print("[" + tasks[x].getStatusIcon() + "] "); + System.out.println(tasks[x].getDescription()); + System.out.println(LINE); + break; + case "unmark": + validateTaskNumber(list_input); + int y = Integer.parseInt(list_input[1]) - 1; + tasks[y].setDone(false); + System.out.println(LINE); + System.out.println("OK, I've marked this task as not done yet:\n"); + System.out.print("[" + tasks[y].getStatusIcon() + "] "); + System.out.println(tasks[y].getDescription()); + System.out.println(LINE); + break; + case "todo": + if (input.trim().length() <= 5) { + throw new PoirotException("Hey, I don't know what you need to do bro!"); + } + String todoDescription = input.substring(5).trim(); + add(new Todo(todoDescription)); + break; + case "deadline": + if (!input.contains("/by")) { + throw new PoirotException("Hey, you haven't set your deadline bro!"); + } + String[] deadlineParts = input.substring(9).split(" /by "); + add(new Deadline(deadlineParts[0], deadlineParts[1])); + break; + case "event": + if (!input.contains("/from") || !input.contains("/to")) { + throw new PoirotException("Hey, what the hell this event's duration bro?"); + } + String[] eventParts = input.substring(6).split(" /from "); + String[] timeParts = eventParts[1].split(" /to "); + add(new Event(eventParts[0], timeParts[0], timeParts[1])); + break; + default: + throw new PoirotException("What the hell you wanna say?"); + } + } catch (PoirotException e) { + echo(e.getMessage()); + } catch (Exception e) { + echo("Something went wrong"); } } System.out.println(LINE); System.out.println("Bye. Hope to see you again soon!"); System.out.println(LINE); } + + private static void validateTaskNumber(String[] list_input) throws PoirotException { + if (list_input.length < 2) { + throw new PoirotException("Task number is missing. Please provide a valid task number."); + } + int index = Integer.parseInt(list_input[1]) - 1; + if (index < 0 || index >= last_index) { + throw new PoirotException("Task number is out of range."); + } + } } \ No newline at end of file diff --git a/src/main/java/PoirotException.java b/src/main/java/PoirotException.java new file mode 100644 index 000000000..e2a4d4b3c --- /dev/null +++ b/src/main/java/PoirotException.java @@ -0,0 +1,5 @@ +public class PoirotException extends Exception{ + public PoirotException(String message){ + super(message); + } +} From b806d12bec2a3d0715165be879e139451b4b9c40 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Wed, 18 Sep 2024 10:35:17 +0800 Subject: [PATCH 08/21] Level 6. Delete --- src/main/java/Poirot.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index ab253c615..eb7c0378a 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -33,7 +33,19 @@ public static void add(Task task) { System.out.println("Now you have " + last_index + " tasks in the list."); System.out.println(LINE); } - + public static void deleteTask(int index) { + Task removedTask = tasks[index]; + for (int i = index; i < last_index - 1; i++) { + tasks[i] = tasks[i + 1]; + } + tasks[last_index - 1] = null; + last_index--; + System.out.println(LINE); + System.out.println("Noted. I've removed this task:"); + System.out.println(" " + removedTask); + System.out.println("Now you have " + last_index + " tasks in the list."); + System.out.println(LINE); + } public static void main(String[] args) { System.out.println(LINE); System.out.println("Hello! I'm POIROT\n"); @@ -94,6 +106,11 @@ public static void main(String[] args) { String[] timeParts = eventParts[1].split(" /to "); add(new Event(eventParts[0], timeParts[0], timeParts[1])); break; + case "delete": + validateTaskNumber(list_input); + int z = Integer.parseInt(list_input[1]) - 1; + deleteTask(z); + break; default: throw new PoirotException("What the hell you wanna say?"); } From b4c70c2c801afb45b87c1aac5707c9777e64de68 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Wed, 18 Sep 2024 13:10:51 +0800 Subject: [PATCH 09/21] Level 7. Save --- src/main/java/Deadline.java | 4 +++ src/main/java/Event.java | 4 +++ src/main/java/Poirot.java | 68 ++++++++++++++++++++++++++++++++++++- src/main/java/Task.java | 1 + src/main/java/Todo.java | 4 +++ 5 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 2a9bd844f..b9473b20d 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -10,4 +10,8 @@ public Deadline(String description, String by) { public String toString() { return "[D][" + getStatusIcon() + "] " + description + " (by: " + by + ")"; } + @Override + public String toFileString() { + return "D | " + (isDone ? "1" : "0") + " | " + description + " | " + by; + } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java index dbe8f8467..9d1804f5a 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -12,4 +12,8 @@ public Event(String description, String from, String to) { public String toString() { return "[E][" + getStatusIcon() + "] " + description + " (from: " + from + " to: " + to + ")"; } + @Override + public String toFileString() { + return "E | " + (isDone ? "1" : "0") + " | " + description + " | " + from + " | " + to; + } } diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index ab253c615..42ef5900b 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -1,8 +1,10 @@ +import java.io.*; import java.util.Scanner; public class Poirot { public static final String LINE = "____________________________________________________________\n"; private static Task[] tasks = new Task[100]; + private static final String FILE_PATH = "./data/duke.txt"; private static int last_index = 0; public static void echo(String msg) { @@ -32,6 +34,65 @@ public static void add(Task task) { System.out.println(" " + task); System.out.println("Now you have " + last_index + " tasks in the list."); System.out.println(LINE); + saveTasksToFile(); + } + + public static void saveTasksToFile() { + try { + File dir = new File("./data"); + if (!dir.exists()) { + dir.mkdirs(); + } + FileWriter writer = new FileWriter(FILE_PATH); + for (int i = 0; i < last_index; i++) { + writer.write(tasks[i].toFileString() + "\n"); + } + writer.close(); + } catch (IOException e) { + System.out.println("Error saving tasks to file: " + e.getMessage()); + } + } + + public static void loadTasksFromFile() { + try { + File file = new File(FILE_PATH); + if (!file.exists()) { + return; // No file to load from + } + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + String[] parts = line.split(" \\| "); + String taskType = parts[0]; + boolean isDone = parts[1].equals("1"); + String description = parts[2]; + + switch (taskType) { + case "T": + add(new Todo(description)); + break; + case "D": + String by = parts[3]; + add(new Deadline(description, by)); + break; + case "E": + String from = parts[3]; + String to = parts[4]; + add(new Event(description, from, to)); + break; + default: + System.out.println("Corrupted data: " + line); + } + } + scanner.close(); + } catch (FileNotFoundException e) { + System.out.println("No saved tasks found."); + } + } + + public static void markTask(int index, boolean isDone) { + tasks[index].setDone(isDone); + saveTasksToFile(); } public static void main(String[] args) { @@ -39,6 +100,9 @@ public static void main(String[] args) { System.out.println("Hello! I'm POIROT\n"); System.out.println("What can I do for you?"); System.out.println(LINE); + + loadTasksFromFile(); + boolean working = true; Scanner scan = new Scanner(System.in); while (working) { @@ -61,6 +125,7 @@ public static void main(String[] args) { System.out.print("[" + tasks[x].getStatusIcon() + "] "); System.out.println(tasks[x].getDescription()); System.out.println(LINE); + saveTasksToFile(); // Save the task after marking it break; case "unmark": validateTaskNumber(list_input); @@ -71,6 +136,7 @@ public static void main(String[] args) { System.out.print("[" + tasks[y].getStatusIcon() + "] "); System.out.println(tasks[y].getDescription()); System.out.println(LINE); + saveTasksToFile(); break; case "todo": if (input.trim().length() <= 5) { @@ -117,4 +183,4 @@ private static void validateTaskNumber(String[] list_input) throws PoirotExcepti throw new PoirotException("Task number is out of range."); } } -} \ No newline at end of file +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index e68e9d5a4..3a35b42b5 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -16,4 +16,5 @@ public void setDone(boolean isDone) { this.isDone = isDone; } public abstract String toString(); + public abstract String toFileString(); } diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index 7b9465a86..8e3c08e54 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -7,4 +7,8 @@ public Todo(String description) { public String toString() { return "[T][" + getStatusIcon() + "] " + description; } + @Override + public String toFileString() { + return "T | " + (isDone ? "1" : "0") + " | " + description; + } } From b1c114fb69dfb81188b9eb920babb4751db423ec Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Thu, 19 Sep 2024 22:54:10 +0800 Subject: [PATCH 10/21] Add saveTasksToFile to delete in Level 7. Save --- src/main/java/Poirot.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index 0444e3280..41a8a82a7 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -176,6 +176,7 @@ public static void main(String[] args) { validateTaskNumber(list_input); int z = Integer.parseInt(list_input[1]) - 1; deleteTask(z); + saveTasksToFile(); break; default: throw new PoirotException("What the hell you wanna say?"); From 3aaa8d4dd0dfc2443f08eb78465164136f0cb360 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Tue, 1 Oct 2024 22:40:48 +0800 Subject: [PATCH 11/21] Make the program more OOP --- src/main/java/AddDeadlineCommand.java | 18 +++ src/main/java/AddEventCommand.java | 20 +++ src/main/java/AddTodoCommand.java | 15 ++ src/main/java/Command.java | 7 + src/main/java/DeleteCommand.java | 18 +++ src/main/java/Event.java | 1 + src/main/java/ExitCommand.java | 11 ++ src/main/java/ListCommand.java | 6 + src/main/java/MarkCommand.java | 17 +++ src/main/java/Parser.java | 25 +++ src/main/java/Poirot.java | 210 +++----------------------- src/main/java/Storage.java | 71 +++++++++ src/main/java/TaskList.java | 33 ++++ src/main/java/Ui.java | 76 ++++++++++ src/main/java/UnmarkCommand.java | 17 +++ 15 files changed, 357 insertions(+), 188 deletions(-) create mode 100644 src/main/java/AddDeadlineCommand.java create mode 100644 src/main/java/AddEventCommand.java create mode 100644 src/main/java/AddTodoCommand.java create mode 100644 src/main/java/Command.java create mode 100644 src/main/java/DeleteCommand.java create mode 100644 src/main/java/ExitCommand.java create mode 100644 src/main/java/ListCommand.java create mode 100644 src/main/java/MarkCommand.java 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 create mode 100644 src/main/java/UnmarkCommand.java diff --git a/src/main/java/AddDeadlineCommand.java b/src/main/java/AddDeadlineCommand.java new file mode 100644 index 000000000..d782ecae3 --- /dev/null +++ b/src/main/java/AddDeadlineCommand.java @@ -0,0 +1,18 @@ +public class AddDeadlineCommand extends Command { + private String description; + private String by; + + public AddDeadlineCommand(String input) { + String[] parts = input.split("/by"); + this.description = parts[0].trim().substring(9).trim(); + this.by = parts[1].trim(); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + Task newTask = new Deadline(description, by); + tasks.add(newTask); + ui.showAddedTask(newTask, tasks.getTaskCount()); + storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount()); + } +} diff --git a/src/main/java/AddEventCommand.java b/src/main/java/AddEventCommand.java new file mode 100644 index 000000000..271562f81 --- /dev/null +++ b/src/main/java/AddEventCommand.java @@ -0,0 +1,20 @@ +public class AddEventCommand extends Command { + private String description; + private String from; + private String to; + + public AddEventCommand(String input) { + String[] parts = input.split("/from|/to"); + this.description = parts[0].trim().substring(6).trim(); + this.from = parts[1].trim(); + this.to = parts[2].trim(); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + Task newTask = new Event(description, from, to); + tasks.add(newTask); + ui.showAddedTask(newTask, tasks.getTaskCount()); + storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount()); + } +} diff --git a/src/main/java/AddTodoCommand.java b/src/main/java/AddTodoCommand.java new file mode 100644 index 000000000..a22f65837 --- /dev/null +++ b/src/main/java/AddTodoCommand.java @@ -0,0 +1,15 @@ +public class AddTodoCommand extends Command { + private String description; + + public AddTodoCommand(String description) { + this.description = description; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + Task newTask = new Todo(description); + tasks.add(newTask); + ui.showAddedTask(newTask, tasks.getTaskCount()); + storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount()); + } +} diff --git a/src/main/java/Command.java b/src/main/java/Command.java new file mode 100644 index 000000000..a29013e24 --- /dev/null +++ b/src/main/java/Command.java @@ -0,0 +1,7 @@ +public abstract class Command { + public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException; + + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/DeleteCommand.java b/src/main/java/DeleteCommand.java new file mode 100644 index 000000000..7cb2cd84f --- /dev/null +++ b/src/main/java/DeleteCommand.java @@ -0,0 +1,18 @@ +public class DeleteCommand extends Command { + private int index; + + public DeleteCommand(int index) { + this.index = index; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException { + if (index < 1 || index > tasks.getTaskCount()) { + throw new PoirotException("Task number is out of bounds!"); + } + Task taskToDelete = tasks.getTask(index - 1); + tasks.delete(index - 1); + ui.showDeletedTask(taskToDelete, tasks.getTaskCount()); + storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount()); + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 9d1804f5a..b1640d5a9 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -12,6 +12,7 @@ public Event(String description, String from, String to) { public String toString() { return "[E][" + getStatusIcon() + "] " + description + " (from: " + from + " to: " + to + ")"; } + @Override public String toFileString() { return "E | " + (isDone ? "1" : "0") + " | " + description + " | " + from + " | " + to; diff --git a/src/main/java/ExitCommand.java b/src/main/java/ExitCommand.java new file mode 100644 index 000000000..40995b345 --- /dev/null +++ b/src/main/java/ExitCommand.java @@ -0,0 +1,11 @@ +public class ExitCommand extends Command { + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.showExit(); + } + + @Override + public boolean isExit() { + return true; + } +} diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java new file mode 100644 index 000000000..864fd529d --- /dev/null +++ b/src/main/java/ListCommand.java @@ -0,0 +1,6 @@ +public class ListCommand extends Command { + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ui.showTaskList(tasks.getTasks(), tasks.getTaskCount()); + } +} diff --git a/src/main/java/MarkCommand.java b/src/main/java/MarkCommand.java new file mode 100644 index 000000000..bdf4f5ba5 --- /dev/null +++ b/src/main/java/MarkCommand.java @@ -0,0 +1,17 @@ +public class MarkCommand extends Command { + private int index; + + public MarkCommand(int index) { + this.index = index; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException { + if (index < 1 || index > tasks.getTaskCount()) { + throw new PoirotException("Task number is out of bounds!"); + } + tasks.markTask(index - 1, true); + ui.showMarkTask(tasks.getTask(index - 1)); + storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount()); + } +} diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..12752b3c6 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,25 @@ +public class Parser { + public static Command parse(String input) throws PoirotException { + String[] list_input = input.split(" "); + switch (list_input[0]) { + case "list": + return new ListCommand(); + case "mark": + return new MarkCommand(Integer.parseInt(list_input[1])); + case "unmark": + return new UnmarkCommand(Integer.parseInt(list_input[1])); + case "todo": + return new AddTodoCommand(input.substring(5).trim()); + case "deadline": + return new AddDeadlineCommand(input); + case "event": + return new AddEventCommand(input); + case "delete": + return new DeleteCommand(Integer.parseInt(list_input[1])); + case "bye": + return new ExitCommand(); + default: + throw new PoirotException("Unknown command!"); + } + } +} diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index 41a8a82a7..9e0354baa 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -1,204 +1,38 @@ -import java.io.*; -import java.util.Scanner; - public class Poirot { - public static final String LINE = "____________________________________________________________\n"; - private static Task[] tasks = new Task[100]; - private static final String FILE_PATH = "./data/duke.txt"; - private static int last_index = 0; - - public static void echo(String msg) { - System.out.println(LINE); - System.out.println(msg); - System.out.println(LINE); - } - public static void print(Task[] tasks) { - if (last_index == 0) { - System.out.println(LINE); - System.out.println("No actions available"); - } else { - System.out.println(LINE); - for (int i = 0; i < last_index; i++) { - System.out.println((i + 1) + "." + tasks[i]); - } - } - System.out.println(LINE); - } + private Storage storage; + private TaskList tasks; + private Ui ui; - public static void add(Task task) { - tasks[last_index] = task; - last_index++; - System.out.println(LINE); - System.out.println("Got it. I've added this task:"); - System.out.println(" " + task); - System.out.println("Now you have " + last_index + " tasks in the list."); - System.out.println(LINE); - saveTasksToFile(); - } + public Poirot(String filePath) { + ui = new Ui(); + storage = new Storage(filePath); + tasks = new TaskList(); - public static void saveTasksToFile() { - try { - File dir = new File("./data"); - if (!dir.exists()) { - dir.mkdirs(); - } - FileWriter writer = new FileWriter(FILE_PATH); - for (int i = 0; i < last_index; i++) { - writer.write(tasks[i].toFileString() + "\n"); + Task[] loadedTasks = storage.loadTasksFromFile(); + for (Task task : loadedTasks) { + if (task != null) { + tasks.add(task); } - writer.close(); - } catch (IOException e) { - System.out.println("Error saving tasks to file: " + e.getMessage()); } } - public static void loadTasksFromFile() { - try { - File file = new File(FILE_PATH); - if (!file.exists()) { - return; // No file to load from - } - Scanner scanner = new Scanner(file); - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); - String[] parts = line.split(" \\| "); - String taskType = parts[0]; - boolean isDone = parts[1].equals("1"); - String description = parts[2]; - - switch (taskType) { - case "T": - add(new Todo(description)); - break; - case "D": - String by = parts[3]; - add(new Deadline(description, by)); - break; - case "E": - String from = parts[3]; - String to = parts[4]; - add(new Event(description, from, to)); - break; - default: - System.out.println("Corrupted data: " + line); - } - } - scanner.close(); - } catch (FileNotFoundException e) { - System.out.println("No saved tasks found."); - } - } - - public static void markTask(int index, boolean isDone) { - tasks[index].setDone(isDone); - saveTasksToFile(); - } - public static void deleteTask(int index) { - Task removedTask = tasks[index]; - for (int i = index; i < last_index - 1; i++) { - tasks[i] = tasks[i + 1]; - } - tasks[last_index - 1] = null; - last_index--; - System.out.println(LINE); - System.out.println("Noted. I've removed this task:"); - System.out.println(" " + removedTask); - System.out.println("Now you have " + last_index + " tasks in the list."); - System.out.println(LINE); - } - public static void main(String[] args) { - System.out.println(LINE); - System.out.println("Hello! I'm POIROT\n"); - System.out.println("What can I do for you?"); - System.out.println(LINE); - - loadTasksFromFile(); - - boolean working = true; - Scanner scan = new Scanner(System.in); - while (working) { - String input = scan.nextLine(); - String[] list_input = input.split(" "); + public void run() { + ui.showWelcome(); + boolean isExit = false; + while (!isExit) { try { - switch (list_input[0]) { - case "list": - print(tasks); - break; - case "bye": - working = false; - break; - case "mark": - validateTaskNumber(list_input); - int x = Integer.parseInt(list_input[1]) - 1; - tasks[x].setDone(true); - System.out.println(LINE); - System.out.println("Nice! I've marked this task as done:\n"); - System.out.print("[" + tasks[x].getStatusIcon() + "] "); - System.out.println(tasks[x].getDescription()); - System.out.println(LINE); - saveTasksToFile(); // Save the task after marking it - break; - case "unmark": - validateTaskNumber(list_input); - int y = Integer.parseInt(list_input[1]) - 1; - tasks[y].setDone(false); - System.out.println(LINE); - System.out.println("OK, I've marked this task as not done yet:\n"); - System.out.print("[" + tasks[y].getStatusIcon() + "] "); - System.out.println(tasks[y].getDescription()); - System.out.println(LINE); - saveTasksToFile(); - break; - case "todo": - if (input.trim().length() <= 5) { - throw new PoirotException("Hey, I don't know what you need to do bro!"); - } - String todoDescription = input.substring(5).trim(); - add(new Todo(todoDescription)); - break; - case "deadline": - if (!input.contains("/by")) { - throw new PoirotException("Hey, you haven't set your deadline bro!"); - } - String[] deadlineParts = input.substring(9).split(" /by "); - add(new Deadline(deadlineParts[0], deadlineParts[1])); - break; - case "event": - if (!input.contains("/from") || !input.contains("/to")) { - throw new PoirotException("Hey, what the hell this event's duration bro?"); - } - String[] eventParts = input.substring(6).split(" /from "); - String[] timeParts = eventParts[1].split(" /to "); - add(new Event(eventParts[0], timeParts[0], timeParts[1])); - break; - case "delete": - validateTaskNumber(list_input); - int z = Integer.parseInt(list_input[1]) - 1; - deleteTask(z); - saveTasksToFile(); - break; - default: - throw new PoirotException("What the hell you wanna say?"); - } + String fullCommand = ui.readCommand(); + Command command = Parser.parse(fullCommand); + command.execute(tasks, ui, storage); + isExit = command.isExit(); } catch (PoirotException e) { - echo(e.getMessage()); - } catch (Exception e) { - echo("Something went wrong"); + ui.showError(e.getMessage()); } } - System.out.println(LINE); - System.out.println("Bye. Hope to see you again soon!"); - System.out.println(LINE); } - private static void validateTaskNumber(String[] list_input) throws PoirotException { - if (list_input.length < 2) { - throw new PoirotException("Task number is missing. Please provide a valid task number."); - } - int index = Integer.parseInt(list_input[1]) - 1; - if (index < 0 || index >= last_index) { - throw new PoirotException("Task number is out of range."); - } + public static void main(String[] args) { + new Poirot("./data/duke.txt").run(); } } diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..53da71afc --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,71 @@ +import java.io.*; +import java.util.Scanner; + +public class Storage { + private String filePath; + + public Storage(String filePath) { + this.filePath = filePath; + } + + public Task[] loadTasksFromFile() { + Task[] tasks = new Task[100]; + int lastIndex = 0; + + try { + File file = new File(filePath); + if (!file.exists()) { + return tasks; + } + + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + String[] parts = line.split(" \\| "); + String taskType = parts[0]; + boolean isDone = parts[1].equals("1"); + String description = parts[2]; + + switch (taskType) { + case "T": + tasks[lastIndex] = new Todo(description); + break; + case "D": + String by = parts[3]; + tasks[lastIndex] = new Deadline(description, by); + break; + case "E": + String from = parts[3]; + String to = parts[4]; + tasks[lastIndex] = new Event(description, from, to); + break; + } + + tasks[lastIndex].setDone(isDone); + lastIndex++; + } + scanner.close(); + } catch (IOException e) { + System.out.println("Error loading tasks from file: " + e.getMessage()); + } + + return tasks; + } + + public void saveTasksToFile(Task[] tasks, int lastIndex) { + try { + File dir = new File("./data"); + if (!dir.exists()) { + dir.mkdirs(); + } + + FileWriter writer = new FileWriter(filePath); + for (int i = 0; i < lastIndex; i++) { + writer.write(tasks[i].toFileString() + "\n"); + } + writer.close(); + } catch (IOException e) { + System.out.println("Error saving tasks to file: " + e.getMessage()); + } + } +} diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 000000000..f6cf756db --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,33 @@ +public class TaskList { + private Task[] tasks = new Task[100]; + private int lastIndex = 0; + + public void add(Task task) { + tasks[lastIndex] = task; + lastIndex++; + } + + public void delete(int index) { + for (int i = index; i < lastIndex - 1; i++) { + tasks[i] = tasks[i + 1]; + } + tasks[lastIndex - 1] = null; + lastIndex--; + } + + public Task[] getTasks() { + return tasks; + } + + public int getTaskCount() { + return lastIndex; + } + + public Task getTask(int index) { + return tasks[index]; + } + + public void markTask(int index, boolean isDone) { + tasks[index].setDone(isDone); + } +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..01cb50d03 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,76 @@ +import java.util.Scanner; + +public class Ui { + private static final String LINE = "____________________________________________________________\n"; + + public void showLine() { + System.out.println(LINE); + } + + public void showWelcome() { + showLine(); + System.out.println("Hello! I'm POIROT\nWhat can I do for you?"); + showLine(); + } + + public void showExit() { + showLine(); + System.out.println("Bye. Hope to see you again soon!"); + showLine(); + } + + public String readCommand() { + Scanner scanner = new Scanner(System.in); + return scanner.nextLine(); + } + + public void showError(String message) { + showLine(); + System.out.println(message); + showLine(); + } + + public void showAddedTask(Task task, int taskCount) { + showLine(); + System.out.println("Got it. I've added this task:"); + System.out.println(" " + task); + System.out.println("Now you have " + taskCount + " tasks in the list."); + showLine(); + } + + public void showDeletedTask(Task task, int taskCount) { + showLine(); + System.out.println("Noted. I've removed this task:"); + System.out.println(" " + task); + System.out.println("Now you have " + taskCount + " tasks in the list."); + showLine(); + } + + public void showTaskList(Task[] tasks, int lastIndex) { + showLine(); + if (lastIndex == 0) { + System.out.println("No actions available"); + } else { + for (int i = 0; i < lastIndex; i++) { + System.out.println((i + 1) + "." + tasks[i]); + } + } + showLine(); + } + + public void showMarkTask(Task task) { + showLine(); + System.out.println("Nice! I've marked this task as done:\n"); + System.out.print("[" + task.getStatusIcon() + "] "); + System.out.println(task.getDescription()); + showLine(); + } + + public void showUnmarkTask(Task task) { + showLine(); + System.out.println("OK, I've marked this task as not done yet:\n"); + System.out.print("[" + task.getStatusIcon() + "] "); + System.out.println(task.getDescription()); + showLine(); + } +} diff --git a/src/main/java/UnmarkCommand.java b/src/main/java/UnmarkCommand.java new file mode 100644 index 000000000..b8d66d8ab --- /dev/null +++ b/src/main/java/UnmarkCommand.java @@ -0,0 +1,17 @@ +public class UnmarkCommand extends Command { + private int index; + + public UnmarkCommand(int index) { + this.index = index; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException { + if (index < 1 || index > tasks.getTaskCount()) { + throw new PoirotException("Task number is out of bounds!"); + } + tasks.markTask(index - 1, false); + ui.showUnmarkTask(tasks.getTask(index - 1)); + storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount()); + } +} From 46e6bef8a23af1f7828833b3542f59945256fe0a Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Tue, 1 Oct 2024 23:01:57 +0800 Subject: [PATCH 12/21] Compile OOP version --- data/duke.txt | 2 ++ src/main/java/Deadline.class | Bin 0 -> 1322 bytes src/main/java/Duke.class | Bin 0 -> 1166 bytes src/main/java/Event.class | Bin 0 -> 1406 bytes src/main/java/META-INF/MANIFEST.MF | 3 +++ src/main/java/Poirot.class | Bin 0 -> 6273 bytes src/main/java/PoirotException.class | Bin 0 -> 230 bytes src/main/java/Task.class | Bin 0 -> 636 bytes src/main/java/Todo.class | Bin 0 -> 1202 bytes src/main/java/data/duke.txt | 2 ++ 10 files changed, 7 insertions(+) create mode 100644 data/duke.txt create mode 100644 src/main/java/Deadline.class create mode 100644 src/main/java/Duke.class create mode 100644 src/main/java/Event.class create mode 100644 src/main/java/META-INF/MANIFEST.MF create mode 100644 src/main/java/Poirot.class create mode 100644 src/main/java/PoirotException.class create mode 100644 src/main/java/Task.class create mode 100644 src/main/java/Todo.class create mode 100644 src/main/java/data/duke.txt diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 000000000..5da82cfb6 --- /dev/null +++ b/data/duke.txt @@ -0,0 +1,2 @@ +T | 0 | sleep +E | 0 | go to school | monday | tuesday diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class new file mode 100644 index 0000000000000000000000000000000000000000..f366fbc360644c6da1359856ab0e4cf6a0d681c9 GIT binary patch literal 1322 zcma)6TTc@~6#k~r?oyUgD~QO&q9E;pT)ayGEp3Px(1#LCAUsUl2`pW9o9>i^#2=!+ zz*kLF5+3{k{wU*_?m{cA#)qBDneRLEopa{w&tK<10IVP%MF?FQx($R8Vd&oGUWFmD zY&n)(Wf)9t9`O@CZ*%8hz94IsbC5~z^gu_ChNyvF7z}z|@Um?=f+18qWk|GhqQr<9 z=trEP??A|cs4Ef%t}Fk&W#N@-R#jTAlOWlH25w-8Vd$7wM9y_e zT)wm9A+0>g9qBQ=?jXDUj&{pmgbW+Fg%L`N<>g%!Cfn69M$@8>+cYgCK&euxykp=l zCK)tONFUmr+D-4MqnH||4Wv{KVw8h?Gb)DZ|5BXZp%UfXGD+y)q=dhz9~VV!n-^`e z=+gBo#9&Bw-Ll2SwvWV3 zu3M>BGwt^Ep%8t@q!V~wM*>T5)y5oH$ffN0VgBTT~ljz04% zuF& zS=AtcjB(Ph;)|FgXP9V8_pfGzr5{Fs9iv$Z3Y%w`x~ft^sjoUf@3lcGghlcb!UH^{ YIYz5TL|kf&%UC5_l=d%>MGnKi0dVLfvH$=8 literal 0 HcmV?d00001 diff --git a/src/main/java/Duke.class b/src/main/java/Duke.class new file mode 100644 index 0000000000000000000000000000000000000000..4fa6a37092247e7c0a35bd2fb90e00d146e25297 GIT binary patch literal 1166 zcmbVL-A)rh6#j+++b&hG2#5*}3fKa&_LB5MC(M zsrUZmT$T;P_;#QI^NJyn%^fC@WQe&>gLlVY#%*!#^J7{>TfEgq`JBXk)8n3nS#cZH z**V`PE#Grn*0#rweSgEJt7D%yzvZUjV!}Z>jcd5x=Vz%I8(Aawbc4K|DYhdBwD%zj zlqs1=idsHH!A_-d0~v<7nyAWxR%Kz10&_-OY=kl~!)msp+zy{K19h6u4T@ac#EgU4 zH0E%NVS31e3{KrXA1d-_m{m&TZHC#SGhujHD8A1tnt#?2Z|cVDB)Cf+*mtBrbo(8V4}pW;EYE{DK-gX}aw z-w)`TD2OmD1xDtR@EFp2G7PDDk*>Lnj{8cEK0 MCGIhv;yLF30AnI8_5c6? literal 0 HcmV?d00001 diff --git a/src/main/java/Event.class b/src/main/java/Event.class new file mode 100644 index 0000000000000000000000000000000000000000..48ae3d5a455e23c5f0b45c0bfc4074c79c72d9e7 GIT binary patch literal 1406 zcmbVM+fEZv6kVsZouN!AEq4(t3fh*tcPOY(ijsgnlwbn#FtkS)TIMt}rz9kPh<<^u znusJk_yK;Dai30wLMt(*IeVYWT6^}jKYyM50I-0UA^6au!EYddAcKFybc+nZdCRus zGluTO+JSjwPL)i1Zz?Ap%ic>TH(Q~jRYS-?8w`d(_K4e($nPC-$PjC!C_=k|h(i0M z2+=WWAcjtc@E(^rY08Sbnin=hS0dS*-)*2r@!JaA%{x|ETEdP|5Pb&vaf6}v&@A$d zu=A#TYsr1uxzey@hCY?* zQ3H2zk3n;}^q~I4R&rB4MU_Yy7*knkr>rbr#K|!GpD`pisV*5&Ag3a0md#&R4tKe; zVeXdbMwh~?DT5)!idEu&j$tZEzPN6dt4IwG7&@*t0z)V#Do&m&A|0w-FsV=kUJ^pO z(lN{HT<(j48wuiR2(y^ekX8koXBfFKXxT@i$ZHMe)o{hkOW__>P^x}A1Uh`3Od&#_2%Av!N%87t`j4RNnIGXMYp literal 0 HcmV?d00001 diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..bf4a2bebf --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Poirot + diff --git a/src/main/java/Poirot.class b/src/main/java/Poirot.class new file mode 100644 index 0000000000000000000000000000000000000000..01ef698c476aa16d2fa607936f4976f6cf8a11be GIT binary patch literal 6273 zcmbtZYhWDJb^h+`N;6uGENO*oOEPBUfGs~HnRO5#$rxL<@y4=jkm_d=d!!vpi&i^g zcVt^BC7~rWl#n!#hiw{C>?8`1P;63J$Y4TC0twJIP1?95X-k?Anzp2rwkcraeCO`U zk}V~FDl>EE-nsYO^Z3qp?hfC1cl;E9m1;!<20|vnHVROvPE6c8-8XwZ zfkI(xGMx;rQwY^9-dY3;MJ6IPieXmDlcmtf}4{=dtyB3u68@FVV>7X;ncE~k{Xjv6J?y)9x< z3Fg|ULbXC9%!QFrs++;KC_;#f_3u+yI8*SahedX5x3Nj^RIpz(lab9fwuplYdQyIt zZnS-9te#)!5nNrq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=P_eg+jPqAuY^VV+J- z!%~%;pDP%P^?8K_qb%_h+8#%3h-5x_#FGC%AjemW|3YdupA9uf&1Jg`ChM6}m+5=0 dzQ0G`uh92J`o37-m#TWMh;Vj;TCQTK`Zeqg;z$4h literal 0 HcmV?d00001 diff --git a/src/main/java/PoirotException.class b/src/main/java/PoirotException.class new file mode 100644 index 0000000000000000000000000000000000000000..8f16cb6441fa67e058c494db2d64b9e3ed5e9237 GIT binary patch literal 230 zcmX^0Z`VEs1_oOOUM>bE24;2!79Ivx1~x_p;jF~6ME#t^ymWonisaOSlFa-(Mg}&U z%)HDJJ4Oak4IhMp;F6-uymV{LFm?tGMh5CI~+Da7&35m9cAXIU4j1?Jzjp7&n3%`IX zNFXE*`~ZFwVqORo#AVmJZ)SFO<%h?+djLPMRDp$pg6*P+l3?^GJPTL5VcJ>!+dhgT zEhv3Y(nS9h6dKL_G8~i@DlSIg3hccwKNgG}#(C6BPIZ!{0)O|vNK5yUw6kGoRTnjk zQZLE3vNRURfdilEpMwdex?r;Lk=oqnn9b~vgxYSB#((-J?YOrWw!7?9JF(t+JA0zh z{3s#th->Lk_w${|SoBy#$G^kVfsVrLyUm|X3sg?^fmOS4V0<__dwFwpww-k2m$K5z z`n@PNEkW5_WyKu9u5)pVm$qP=i}A}gS70tdc=AccPpsC6Ft}Q93kjBQpn}2;yeqZ@ zpBa4;L4r+U846Vj3#KqV6qsceg9xsnE?;S83Q%GE@(NuaLTiM2=WzV73l#lvL$U_5 yo=F~N*io?DUkYEz`Gz@0<91=_wiL{~GiiP%aJwSLY(bq9!8~s=nG1{-7M}n~9c+RC literal 0 HcmV?d00001 diff --git a/src/main/java/Todo.class b/src/main/java/Todo.class new file mode 100644 index 0000000000000000000000000000000000000000..c7fb420033930ab13f98a442ae08cbe028f4895a GIT binary patch literal 1202 zcmaJ>T~8B16g^W)cUzW%6$C`EAYfaR4?od@h$Tc4(1$jfKzNvLC$MzcX?CY1B>oWn z1-@!xB;mmy;EyuiVOOZM`q25fJ?G55XYTCJUuQo6tl(t|F?1P-Tj)lDAztA@oguO8 zc#e9(FqqpqzP%0dq;O_DXq(7P{GS#i}2Hf`xK4CM0d zTt#&bK`ix`r6n6faf z-AI!S>#c>wOR`47eOrzv-ZYP@!mseEOA%Aa&{76V$qmO9f405kqg~(TjdP@ddkp`4TF{rkVhRuN(7+?@=VOMcOFhRsmUR(b zZ)oubx0Uoy7(TX|8v#Sn*W9bQBAD8evfgYI+Z}I-{6(ysG(-pZZVUcx^-$QV*m`G? zM2Wj@*-@fs;wd?}TiM%Xds$}UnYJMNA?ItOzkc6Mpa$%*@DVbZ16G_E^Y{ou3-AEfh$@K+IY* zFx$VTyE!_3oTS2ZM^7<+nQlmAgr#>LVaI6J$#fS^F?lsZ4W&oW0eYtmN;cdlofzgY aPji}93q*W!J}%)o#Zt5{(pPE~BfkN^MFj!? literal 0 HcmV?d00001 diff --git a/src/main/java/data/duke.txt b/src/main/java/data/duke.txt new file mode 100644 index 000000000..53200bb40 --- /dev/null +++ b/src/main/java/data/duke.txt @@ -0,0 +1,2 @@ +T | 0 | sleep +T | 0 | work From 1b9df271ae4f7a834a18f335301691e0e86e8a18 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Wed, 2 Oct 2024 00:40:06 +0800 Subject: [PATCH 13/21] Level 8. Dates and Times --- src/main/java/AddDeadlineCommand.java | 18 ++++++++++++++---- src/main/java/Deadline.class | Bin 1322 -> 1932 bytes src/main/java/Deadline.java | 16 +++++++++++----- src/main/java/Poirot.class | Bin 6273 -> 1236 bytes 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/AddDeadlineCommand.java b/src/main/java/AddDeadlineCommand.java index d782ecae3..39eef3e12 100644 --- a/src/main/java/AddDeadlineCommand.java +++ b/src/main/java/AddDeadlineCommand.java @@ -1,6 +1,11 @@ +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + public class AddDeadlineCommand extends Command { private String description; private String by; + private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"); public AddDeadlineCommand(String input) { String[] parts = input.split("/by"); @@ -10,9 +15,14 @@ public AddDeadlineCommand(String input) { @Override public void execute(TaskList tasks, Ui ui, Storage storage) { - Task newTask = new Deadline(description, by); - tasks.add(newTask); - ui.showAddedTask(newTask, tasks.getTaskCount()); - storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount()); + try { + LocalDateTime.parse(by, INPUT_FORMAT); // Validate the date format + Task newTask = new Deadline(description, by); + tasks.add(newTask); + ui.showAddedTask(newTask, tasks.getTaskCount()); + storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount()); + } catch (DateTimeParseException e) { + ui.showError("Invalid date format. Please use yyyy-MM-dd HHmm format."); + } } } diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class index f366fbc360644c6da1359856ab0e4cf6a0d681c9..830d4fbfdca291f7ed2305e26ae27b94ce730f2c 100644 GIT binary patch literal 1932 zcma)6>r&fB6#mwLC5!;aga(p^sFXCe0|9zXF-c485=d>Jv4Iv!)3v+-1zU2ZB{R(Q zLE0zi-!^SSCO`TBeW*^)N+MRcWa1g^*S3}A`9}EV)BzU7~JA%PjURhhO zJz89SSXrnsOoZCfZi(r~uGivny2PcZ(RndAO5qh!7{H*0w1ErAFkA{81}bIO;>}|P zhMqR}d~&iG530Dwy{h=>Ksc5typ6kD4D_0Vf=cV6fnmJEkfAW z`vxX(ogOJ7u zYWdv2oO*x(dVo@gQXTUQgNO8+s#K;L4RdL!)k@(mzR>Wcfd$-S81EF>d3DLq>pouN zl1h|b>6qjAGsP?EJSznqC5E9&rD8Tr71N}-w>Q^nnVgb*D`ImS)RslJK}-#nsmWFj zT6N*oc)dwCx^%-Aq1Kb`qTLk7$9^hFYrn$V0a8PmA$_uyNq^p=#tmA%E2})Es_ubj z31x|D@3^sVDNQnP&vm6QJ>ISex#u?g!6d3F)Ud8$L)FnHwS32k?L2k&MKm_T(puz} zbU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 00:00:00 2001 From: Trung Bui Date: Wed, 2 Oct 2024 00:51:34 +0800 Subject: [PATCH 14/21] Level 9. Find --- src/main/java/FindCommand.java | 19 +++++++++++++++++++ src/main/java/Parser.java | 2 ++ src/main/java/TaskList.java | 11 +++++++++++ src/main/java/Ui.java | 10 ++++++++++ 4 files changed, 42 insertions(+) create mode 100644 src/main/java/FindCommand.java diff --git a/src/main/java/FindCommand.java b/src/main/java/FindCommand.java new file mode 100644 index 000000000..f2963c01c --- /dev/null +++ b/src/main/java/FindCommand.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; + +public class FindCommand extends Command { + private String keyword; + + public FindCommand(String keyword) { + this.keyword = keyword.trim(); + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) { + ArrayList foundTasks = tasks.findTasks(keyword); + if (foundTasks.isEmpty()) { + ui.showMessage("No tasks found with the keyword: " + keyword); + } else { + ui.showFoundTasks(foundTasks); + } + } +} diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index 12752b3c6..0c0cea9c7 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -16,6 +16,8 @@ public static Command parse(String input) throws PoirotException { return new AddEventCommand(input); case "delete": return new DeleteCommand(Integer.parseInt(list_input[1])); + case "find": + return new FindCommand(input); case "bye": return new ExitCommand(); default: diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index f6cf756db..9ff781fbf 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; public class TaskList { private Task[] tasks = new Task[100]; private int lastIndex = 0; @@ -7,6 +8,16 @@ public void add(Task task) { lastIndex++; } + public ArrayList findTasks(String keyword) { + ArrayList foundTasks = new ArrayList<>(); + for (int i = 0; i < lastIndex; i++) { + if (tasks[i].getDescription().toLowerCase().contains(keyword.toLowerCase())) { + foundTasks.add(tasks[i]); + } + } + return foundTasks; + } + public void delete(int index) { for (int i = index; i < lastIndex - 1; i++) { tasks[i] = tasks[i + 1]; diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 01cb50d03..9bc8d4243 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,4 +1,5 @@ import java.util.Scanner; +import java.util.ArrayList; public class Ui { private static final String LINE = "____________________________________________________________\n"; @@ -73,4 +74,13 @@ public void showUnmarkTask(Task task) { System.out.println(task.getDescription()); showLine(); } + public void showFoundTasks(ArrayList tasks) { + System.out.println("Here are the matching tasks in your list:"); + for (int i = 0; i < tasks.size(); i++) { + System.out.println((i + 1) + ". " + tasks.get(i).toString()); + } + } + public void showMessage(String message) { + System.out.println(message); + } } From 5ce99e11f2dddf2eaf5a29dc1fc86909123a1ccd Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Thu, 3 Oct 2024 21:07:31 +0800 Subject: [PATCH 15/21] Fix bugs of Deadline and Event --- src/main/java/AddEventCommand.java | 9 +++--- src/main/java/Event.class | Bin 1406 -> 2053 bytes src/main/java/Parser.java | 47 +++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/main/java/AddEventCommand.java b/src/main/java/AddEventCommand.java index 271562f81..40f929fee 100644 --- a/src/main/java/AddEventCommand.java +++ b/src/main/java/AddEventCommand.java @@ -3,11 +3,10 @@ public class AddEventCommand extends Command { private String from; private String to; - public AddEventCommand(String input) { - String[] parts = input.split("/from|/to"); - this.description = parts[0].trim().substring(6).trim(); - this.from = parts[1].trim(); - this.to = parts[2].trim(); + public AddEventCommand(String description, String from, String to) { + this.description = description; + this.from = from; + this.to = to; } @Override diff --git a/src/main/java/Event.class b/src/main/java/Event.class index 48ae3d5a455e23c5f0b45c0bfc4074c79c72d9e7..44b00bde7460821bed77b248b2fc2385917a0908 100644 GIT binary patch literal 2053 zcmbVMZC4XV6n-WIHpJy^!6Kp{Hd}H* zcnwQR?lDY+#?ooyirR7SW;Yqv#QCFPI z`dv;=NkK7lLq`EO=|YY_CtRvITT9_161P(Lgv3n)45sSc&vo3!9R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S$Qa?>A~z /by "); + } + String description = parts[0].trim().substring(9).trim(); + String by = parts[1].trim(); + return new AddDeadlineCommand(description + " /by " + by); + } catch (ArrayIndexOutOfBoundsException e) { + throw new PoirotException("Invalid format for deadline command."); + } + } + + private static Command parseEventCommand(String input) throws PoirotException { + try { + if (!input.contains("/from") || !input.contains("/to")) { + throw new PoirotException("Invalid event format! Use: event /from /to "); + } + + String[] fromParts = input.split("/from"); + if (fromParts.length < 2) { + throw new PoirotException("Invalid event format! Use: event /from /to "); + } + + String description = fromParts[0].trim().substring(6).trim(); + + String[] toParts = fromParts[1].split("/to"); + if (toParts.length < 2) { + throw new PoirotException("Invalid event format! Use: event /from /to "); + } + + String from = toParts[0].trim(); + String to = toParts[1].trim(); + + return new AddEventCommand(description, from, to); + } catch (StringIndexOutOfBoundsException e) { + throw new PoirotException("Error extracting event description. Please check your input format."); + } + } + + } From 134e8fe86afd20826ce105a50e1ae440a57f2189 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Thu, 3 Oct 2024 21:08:21 +0800 Subject: [PATCH 16/21] Add JavaDocs comments --- src/main/java/AddDeadlineCommand.java | 18 +++++++-- src/main/java/AddTodoCommand.java | 17 ++++++++- src/main/java/DeleteCommand.java | 17 ++++++++- src/main/java/Event.java | 36 +++++++++++++++--- src/main/java/ExitCommand.java | 16 +++++++- src/main/java/FindCommand.java | 15 ++++++++ src/main/java/ListCommand.java | 10 +++++ src/main/java/MarkCommand.java | 16 ++++++++ src/main/java/Storage.java | 22 +++++++++-- src/main/java/Task.class | Bin 636 -> 636 bytes src/main/java/Task.java | 24 +++++++++++- src/main/java/TaskList.java | 41 +++++++++++++++++--- src/main/java/Todo.class | Bin 1202 -> 1202 bytes src/main/java/Todo.java | 19 +++++++++- src/main/java/Ui.java | 52 ++++++++++++++++++++++---- src/main/java/data/duke.txt | 6 ++- 16 files changed, 277 insertions(+), 32 deletions(-) diff --git a/src/main/java/AddDeadlineCommand.java b/src/main/java/AddDeadlineCommand.java index 39eef3e12..49a545d51 100644 --- a/src/main/java/AddDeadlineCommand.java +++ b/src/main/java/AddDeadlineCommand.java @@ -1,18 +1,30 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; - +/** + * Command to add a deadline task. + */ public class AddDeadlineCommand extends Command { private String description; private String by; private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"); - + /** + * Constructs an AddDeadlineCommand with the specified input. + * + * @param input The user input containing the task description and deadline. + */ public AddDeadlineCommand(String input) { String[] parts = input.split("/by"); this.description = parts[0].trim().substring(9).trim(); this.by = parts[1].trim(); } - + /** + * Executes the command to add the deadline task to the task list. + * + * @param tasks The task list to which the task will be added. + * @param ui The user interface for displaying messages to the user. + * @param storage The storage for saving tasks to a file. + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { try { diff --git a/src/main/java/AddTodoCommand.java b/src/main/java/AddTodoCommand.java index a22f65837..cfbcbee31 100644 --- a/src/main/java/AddTodoCommand.java +++ b/src/main/java/AddTodoCommand.java @@ -1,10 +1,23 @@ +/** + * Command to add a todo task. + */ public class AddTodoCommand extends Command { private String description; - + /** + * Constructs an AddTodoCommand with the specified description. + * + * @param description The description of the todo task. + */ public AddTodoCommand(String description) { this.description = description; } - + /** + * Executes the command to add the todo task to the task list. + * + * @param tasks The task list to which the task will be added. + * @param ui The user interface for displaying messages to the user. + * @param storage The storage for saving tasks to a file. + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { Task newTask = new Todo(description); diff --git a/src/main/java/DeleteCommand.java b/src/main/java/DeleteCommand.java index 7cb2cd84f..04aef79d9 100644 --- a/src/main/java/DeleteCommand.java +++ b/src/main/java/DeleteCommand.java @@ -1,10 +1,25 @@ +/** + * Command to delete a task from the task list. + */ public class DeleteCommand extends Command { private int index; - + /** + * Constructs a DeleteCommand with the specified index. + * + * @param index The index of the task to delete. + */ public DeleteCommand(int index) { this.index = index; } + /** + * Executes the command to delete the specified task from the task list. + * + * @param tasks The task list from which the task will be deleted. + * @param ui The user interface for displaying messages to the user. + * @param storage The storage for saving tasks to a file. + * @throws PoirotException If the index is out of bounds. + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException { if (index < 1 || index > tasks.getTaskCount()) { diff --git a/src/main/java/Event.java b/src/main/java/Event.java index b1640d5a9..0e049dc38 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -1,20 +1,44 @@ +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + public class Event extends Task { - private String from; - private String to; + private LocalDateTime from; + private LocalDateTime to; + private static final DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"); + private static final DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm"); + /** + * Constructs an Event with the specified description, from, and to time. + * + * @param description The description of the event. + * @param from The starting time of the event in 'yyyy-MM-dd HHmm' format. + * @param to The ending time of the event in 'yyyy-MM-dd HHmm' format. + */ public Event(String description, String from, String to) { super(description); - this.from = from; - this.to = to; + this.from = LocalDateTime.parse(from, inputFormatter); + this.to = LocalDateTime.parse(to, inputFormatter); } + /** + * Returns a string representation of the event task. + * + * @return A formatted string of the event task. + */ @Override public String toString() { - return "[E][" + getStatusIcon() + "] " + description + " (from: " + from + " to: " + to + ")"; + return "[E][" + getStatusIcon() + "] " + description + " (from: " + + from.format(outputFormatter) + " to: " + to.format(outputFormatter) + ")"; } + /** + * Returns a string representation for saving the event task to a file. + * + * @return A formatted string of the event task for file storage. + */ @Override public String toFileString() { - return "E | " + (isDone ? "1" : "0") + " | " + description + " | " + from + " | " + to; + return "E | " + (isDone ? "1" : "0") + " | " + description + " | " + + from.format(inputFormatter) + " | " + to.format(inputFormatter); } } diff --git a/src/main/java/ExitCommand.java b/src/main/java/ExitCommand.java index 40995b345..ed9d0b986 100644 --- a/src/main/java/ExitCommand.java +++ b/src/main/java/ExitCommand.java @@ -1,9 +1,23 @@ +/** + * Command to exit the application. + */ public class ExitCommand extends Command { + /** + * Executes the command to exit the application. + * + * @param tasks The task list (not used). + * @param ui The user interface for displaying messages to the user. + * @param storage The storage for saving tasks to a file (not used). + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { ui.showExit(); } - + /** + * Indicates whether this command is an exit command. + * + * @return true, since this command is an exit command. + */ @Override public boolean isExit() { return true; diff --git a/src/main/java/FindCommand.java b/src/main/java/FindCommand.java index f2963c01c..65ae8ce72 100644 --- a/src/main/java/FindCommand.java +++ b/src/main/java/FindCommand.java @@ -1,12 +1,27 @@ import java.util.ArrayList; +/** + * Command to find tasks matching a specified keyword. + */ public class FindCommand extends Command { private String keyword; + /** + * Constructs a FindCommand with the specified keyword. + * + * @param keyword The keyword to search for in the task descriptions. + */ public FindCommand(String keyword) { this.keyword = keyword.trim(); } + /** + * Executes the command to find tasks in the task list that match the keyword. + * + * @param tasks The task list to search for matching tasks. + * @param ui The user interface for displaying messages to the user. + * @param storage The storage for saving tasks to a file (not used). + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { ArrayList foundTasks = tasks.findTasks(keyword); diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java index 864fd529d..e6ab13067 100644 --- a/src/main/java/ListCommand.java +++ b/src/main/java/ListCommand.java @@ -1,4 +1,14 @@ +/** + * Command to list all tasks in the task list. + */ public class ListCommand extends Command { + /** + * Executes the command to display the list of tasks. + * + * @param tasks The task list to display. + * @param ui The user interface for displaying messages to the user. + * @param storage The storage for saving tasks to a file (not used). + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { ui.showTaskList(tasks.getTasks(), tasks.getTaskCount()); diff --git a/src/main/java/MarkCommand.java b/src/main/java/MarkCommand.java index bdf4f5ba5..0dde56510 100644 --- a/src/main/java/MarkCommand.java +++ b/src/main/java/MarkCommand.java @@ -1,10 +1,26 @@ +/** + * Command to mark a task as done. + */ public class MarkCommand extends Command { private int index; + /** + * Constructs a MarkCommand with the specified index. + * + * @param index The index of the task to mark as done. + */ public MarkCommand(int index) { this.index = index; } + /** + * Executes the command to mark the specified task as done. + * + * @param tasks The task list containing the task to mark. + * @param ui The user interface for displaying messages to the user. + * @param storage The storage for saving tasks to a file. + * @throws PoirotException If the index is out of bounds. + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException { if (index < 1 || index > tasks.getTaskCount()) { diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index 53da71afc..dd59da6f9 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,13 +1,24 @@ import java.io.*; import java.util.Scanner; - +/** + * Handles loading and saving tasks to a file. + */ public class Storage { private String filePath; - + /** + * Constructs a Storage object with the specified file path. + * + * @param filePath The path of the file to load/save tasks. + */ public Storage(String filePath) { this.filePath = filePath; } + /** + * Loads tasks from the file and returns them as an array. + * + * @return An array of loaded tasks. + */ public Task[] loadTasksFromFile() { Task[] tasks = new Task[100]; int lastIndex = 0; @@ -51,7 +62,12 @@ public Task[] loadTasksFromFile() { return tasks; } - + /** + * Saves the specified tasks to the file. + * + * @param tasks The tasks to save. + * @param lastIndex The number of tasks to save. + */ public void saveTasksToFile(Task[] tasks, int lastIndex) { try { File dir = new File("./data"); diff --git a/src/main/java/Task.class b/src/main/java/Task.class index a4f3641379430d14b8e13825efbb60191c7b535c..48e01303af5083e2731593fe5f9d1a27da0be331 100644 GIT binary patch delta 69 zcmeyv@`q)^4n|%c1{MZh22KV(AmpEXlu?UOaPkL66Gq9&s!SI0iVUm_N-T^F3Jj7A S3_w~DL^CilC;>?(24w)ln+Z(- delta 69 zcmeyv@`q)^4n|&91{MZ322KWc20jLk$wwKr7`Y~YU^HRmovg}aAuqtd${@(X$e_R= U$-n@l6+tuuBZCr findTasks(String keyword) { } return foundTasks; } - + /** + * Deletes a task from the task list at the specified index. + * + * @param index The index of the task to delete. + */ public void delete(int index) { for (int i = index; i < lastIndex - 1; i++) { tasks[i] = tasks[i + 1]; @@ -25,19 +38,37 @@ public void delete(int index) { tasks[lastIndex - 1] = null; lastIndex--; } - + /** + * Returns the list of tasks. + * + * @return The list of tasks. + */ public Task[] getTasks() { return tasks; } - + /** + * Returns the number of tasks in the task list. + * + * @return The count of tasks. + */ public int getTaskCount() { return lastIndex; } - + /** + * Returns the task at the specified index. + * + * @param index The index of the task to retrieve. + * @return The task at the specified index. + */ public Task getTask(int index) { return tasks[index]; } - + /** + * Marks the specified task as done. + * + * @param index The index of the task to mark. + * @param isDone true to mark as done, false otherwise. + */ public void markTask(int index, boolean isDone) { tasks[index].setDone(isDone); } diff --git a/src/main/java/Todo.class b/src/main/java/Todo.class index c7fb420033930ab13f98a442ae08cbe028f4895a..762beebf1f20189d983474789ab87c146c02c34e 100644 GIT binary patch delta 47 ycmdnQxruW_9WyI811kg1 tasks) { System.out.println("Here are the matching tasks in your list:"); for (int i = 0; i < tasks.size(); i++) { diff --git a/src/main/java/data/duke.txt b/src/main/java/data/duke.txt index 53200bb40..7706568b1 100644 --- a/src/main/java/data/duke.txt +++ b/src/main/java/data/duke.txt @@ -1,2 +1,6 @@ -T | 0 | sleep +T | 1 | sleep T | 0 | work +T | 0 | go to work +D | 0 | t | 2025-04-01 1800 +E | 0 | party | 2025-04-01 1800 | 2025-04-01 2100 +D | 0 | work | 2025-04-01 1800 From 2e236e97c91561bdfd0d22dda67a5b28be931e31 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Fri, 4 Oct 2024 04:07:13 +0800 Subject: [PATCH 17/21] Update name in README.md --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 47b9f984f..e3658c491 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Duke User Guide +# Poirot User Guide // Update the title above to match the actual product name From b8554587409cc8c06c34c231aa4a806e18cbbfdd Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Fri, 11 Oct 2024 10:36:11 +0800 Subject: [PATCH 18/21] Update all features in README.md --- docs/README.md | 107 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index e3658c491..b5ea989aa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,30 +1,113 @@ + # Poirot User Guide -// Update the title above to match the actual product name +Poirot is a powerful command-line task management application designed to help you organize your to-dos, deadlines, and events efficiently. + +## Adding a To-Do + +Add tasks without any specific deadline or time, allowing you to track general tasks. -// Product screenshot goes here +Example: `todo Buy groceries` -// Product intro goes here +This command adds a new to-do task to your list. + +``` +____________________________________________________________ +Got it. I've added this task: + [T][ ] Buy groceries +Now you have 1 tasks in the list. +____________________________________________________________ +``` ## Adding deadlines -// Describe the action and its outcome. +Add tasks with specific due dates and times to keep track of important deadlines. + +Example: `deadline Submit report /by 2023-12-31 2359` + +This command adds a new deadline task to your list. + +``` +____________________________________________________________ +Got it. I've added this task: + [D][ ] Submit report (by: Dec 31 2023, 11:59 PM) +Now you have 1 tasks in the list. +____________________________________________________________ +``` + +## Adding events + +Create events with start and end times to manage your schedule effectively. + +Example: `event Team meeting /from 2023-11-15 1400 /to 2023-11-15 1500` + +This command adds a new event to your task list. + +``` +____________________________________________________________ +Got it. I've added this task: + [E][ ] Team meeting (from: Nov 15 2023, 02:00 PM to: Nov 15 2023, 03:00 PM) +Now you have 2 tasks in the list. +____________________________________________________________ +``` + +## Listing tasks -// Give examples of usage +View all your current tasks in one place. -Example: `keyword (optional arguments)` +Example: `list` -// A description of the expected outcome goes here +This command displays all tasks currently in your list. ``` -expected output +____________________________________________________________ +1.[D][ ] Submit report (by: Dec 31 2023, 11:59 PM) +2.[E][ ] Team meeting (from: Nov 15 2023, 02:00 PM to: Nov 15 2023, 03:00 PM) +____________________________________________________________ ``` -## Feature ABC +## Marking tasks as done -// Feature details +Keep track of your progress by marking completed tasks. +Example: `mark 1` -## Feature XYZ +This command marks the first task in your list as done. + +``` +____________________________________________________________ +Nice! I've marked this task as done: + +[X] Submit report +____________________________________________________________ +``` + +## Finding tasks + +Quickly locate tasks related to specific keywords. + +Example: `find report` + +This command searches for tasks containing the word "report". + +``` +Here are the matching tasks in your list: +1. [D][X] Submit report (by: Dec 31 2023, 11:59 PM) +``` + +## Deleting tasks + +Remove tasks that are no longer needed. + +Example: `delete 2` + +This command deletes the second task in your list. + +``` +____________________________________________________________ +Noted. I've removed this task: + [E][ ] Team meeting (from: Nov 15 2023, 02:00 PM to: Nov 15 2023, 03:00 PM) +Now you have 1 tasks in the list. +____________________________________________________________ +``` -// Feature details \ No newline at end of file From edee1a414adebe593321a7060e2507164c46a2d7 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Fri, 11 Oct 2024 10:46:53 +0800 Subject: [PATCH 19/21] rebuild ip.jar --- src/main/java/data/duke.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/data/duke.txt b/src/main/java/data/duke.txt index 7706568b1..6da49ffc3 100644 --- a/src/main/java/data/duke.txt +++ b/src/main/java/data/duke.txt @@ -4,3 +4,4 @@ T | 0 | go to work D | 0 | t | 2025-04-01 1800 E | 0 | party | 2025-04-01 1800 | 2025-04-01 2100 D | 0 | work | 2025-04-01 1800 +T | 0 | mini project From 42416acbfd06bf39b4e7f3a24a09c10f97796f72 Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Fri, 11 Oct 2024 10:52:21 +0800 Subject: [PATCH 20/21] Update classes --- src/main/java/AddDeadlineCommand.class | Bin 0 -> 1554 bytes src/main/java/AddEventCommand.class | Bin 0 -> 759 bytes src/main/java/AddTodoCommand.class | Bin 0 -> 646 bytes src/main/java/Command.class | Bin 0 -> 334 bytes src/main/java/DeleteCommand.class | Bin 0 -> 788 bytes src/main/java/ExitCommand.class | Bin 0 -> 357 bytes src/main/java/FindCommand.class | Bin 0 -> 1200 bytes src/main/java/ListCommand.class | Bin 0 -> 406 bytes src/main/java/MarkCommand.class | Bin 0 -> 779 bytes src/main/java/Parser.class | Bin 0 -> 3001 bytes src/main/java/Storage.class | Bin 0 -> 2588 bytes src/main/java/TaskList.class | Bin 0 -> 1308 bytes src/main/java/Ui.class | Bin 0 -> 3128 bytes src/main/java/UnmarkCommand.class | Bin 0 -> 785 bytes 14 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/java/AddDeadlineCommand.class create mode 100644 src/main/java/AddEventCommand.class create mode 100644 src/main/java/AddTodoCommand.class create mode 100644 src/main/java/Command.class create mode 100644 src/main/java/DeleteCommand.class create mode 100644 src/main/java/ExitCommand.class create mode 100644 src/main/java/FindCommand.class create mode 100644 src/main/java/ListCommand.class create mode 100644 src/main/java/MarkCommand.class create mode 100644 src/main/java/Parser.class create mode 100644 src/main/java/Storage.class create mode 100644 src/main/java/TaskList.class create mode 100644 src/main/java/Ui.class create mode 100644 src/main/java/UnmarkCommand.class diff --git a/src/main/java/AddDeadlineCommand.class b/src/main/java/AddDeadlineCommand.class new file mode 100644 index 0000000000000000000000000000000000000000..2f3dc3ddfd4f18af70e742562a913ae48dfe00d7 GIT binary patch literal 1554 zcma)6ZBr9h7(F+MY_hp3jUa`J28yx?fmrJcWvP`0D5(jiCP1xi^(K48t;sI#ZcxTw z;jidtwMNIz_yhb=ojx~N)FC)yX0rF~-1EGg=eh6xd-E2+_YgWFh-!#&9KisCR&ZM_ z;aCgOV;KBP?23F-INSMZ;MvYL!x4X{X$K6` zM(N<8nYrD+rx*u0zCem0MjS1MAtQ4*Zir(TCm9lcyY7efhK=GO=mfsRsD?3)uW*VX zwPab#Qdmvfk?$i+TGDTL_D*2C4ng`&Dw5M2XB0!EzNeNG9FzE(ffv^+8?`&DH*S`f zY7A4o%YogJ`FpO{587W9rQ|k5bN>RRa7TE) zWZ3#Rg@yaVtICIM=`^JIIp)Hw^cyfW%rM0F^PwY)StbA6;iC2DC9|pHJigIzf#X|T zB(9q9ACzpLWRD7qiYH-|)Rx&pUgo%hc}m*04AgePZ958TWQsZ#K>jRpszs``$cD{u z)W7dOBEh7kzzljwR_w7|<5!xER2fsCE1u_i48tF5-RmXFUK}^c^#fEoYS_@Q z$+3lB874pJ_WRN!Q|`Tr2&f9F(&rB|^*I$q4O(z5mCO?L(R#a8mtIZORWddCST@=L z&Bl6ascJAw8@5>rC7@_X+G-#g56WUEycS<*Gt%F$b1F@ZBtpKlJ8>zmZ&sC_f`kU>+ul6qEAc91`?B zL)Oz2;RMAui5$f^PbVg(sAJBeKtBCJC=HP(8j2d?_!9%6dlOwsAd&jzHL5R={t%sl NfL>mPJ2Xac_kaIvcsc+8 literal 0 HcmV?d00001 diff --git a/src/main/java/AddEventCommand.class b/src/main/java/AddEventCommand.class new file mode 100644 index 0000000000000000000000000000000000000000..5f5e86d7c9d333b1d4c5fe956c3e660fe20a4656 GIT binary patch literal 759 zcma)4TW`}a7(Gt2dQH8pTf2>J+y)HNv|ZV_(}9F4kS0aEw3`GxWsNC;HAYEV_*+PA zCxOHd;71`oHxUoxg%^MJ@$vaC$G?7m{|Vq39$PSw<1hslkZ0f>H5_`O&yYV1!XSCh zkh5zi1uUY#VF?r=7*<~R{>!lplfUeuFXMg`d`^Ty237^uG+-o(qr$K-7qw8vhOTFm;fejP)c+v06AM*racm1*#ubLeo)>>| zgE*mvJfHe2*sg}!Df61Zb?h*RflM^qQKL{(?b?xro4CcXD{vcksMh0vVJZHgzR(b) zugMHnCU%sn)dU>WDQTt_>vXkuX+jH4>~XXN?qZ)N-c3~G4J1u9_Qq1{#Xa>ZI3uKJ zXKzTC#@123rnx~VUyp{TGU|D!n#Sc<*&ije+e+)ueYV}>pzUVj)Fl=^Nn; z_h{Xq7eJnv9P@ubYZ(^Z-p7MX=`C?I>);2|z!B^urh)lCptEe*k!MmID9) literal 0 HcmV?d00001 diff --git a/src/main/java/AddTodoCommand.class b/src/main/java/AddTodoCommand.class new file mode 100644 index 0000000000000000000000000000000000000000..75b669e168fa0e6364c7c6bbb47d3b82569e2063 GIT binary patch literal 646 zcmZWmT~8B16g{(D7`mMn0r_b03qjo70u>*vnwTagBpV-WAt5{s-ANgtJ7#x_{4EkK zi6;I4f0W@4yU`e5?%cWe+;cz9uixK)0(gU$9voCST!9(PGVq=mk7W`w%)Zu%&fhXr z{NSjHIaE13ff@uu<6RsNOlF23VMqQ2ugKKL% z)N#*tTVPoB|3?N#9+q&QV_9GYs|<4knVm;E%V`uD(_~dYvY~E)Yznln&LBoAx8a_d zBo^ui2Ob{c5yxYJC)i+c4mCqPJ2PKsd=*oL9-hPJ z2n0g3=~n&Rq;jMf<}-PzEMGP-@AU;mYJOQmytH`F#1<0lcF%5fsJl@~PFvEDeKSdis-Rx__xOAE*4Q9{98#3Fv=Wi$kWWV@yFpoI$hO*%g)Q`ij;5V3m<+hvd6pK4ew>`z$ j6c2XkeOmb2e|cB#Dp!edjTCK?7%c=?C*~K#=wSaAA|!r$ literal 0 HcmV?d00001 diff --git a/src/main/java/Command.class b/src/main/java/Command.class new file mode 100644 index 0000000000000000000000000000000000000000..e120c8d97985ad59d773228ae1c381fcd9f03c18 GIT binary patch literal 334 zcmYjMyH3L}6g_T|8cLw$F;!wSV1X!vvMS#@Ofz3&+%B6`>;-GvK3lkCpAHYW; zjwOV!ZjDyE=eCulFps2)LJLw zr9f}i=K9$gTh$cDLXs$Aa~FB1Rmap9K^&meh=e*uKQ zhIW_UDNzuk^LL0h5>BD@Y4T8D4>9>Zy^wgoKfocaZypkTT_0Dr{9 zA23mxXrk|alyM(G5?}V&m$mlw{QmR(CxCtInb43hpj${{g~4db;m{8QhLuMm6!Bw* zgySBjkwV&lX(0oPA^U_6c+8jBqzD5(VPGv2IjkBuW8p0F45^ME9eE;(8LU2!mDQBv zkW9+jGH{Mz^_3JO89$x$_;D;`n8JC6vO?P7c-ZA5TST@T$F_WHcZnNB6%z$qR1Fsy z)*SD>f8y5%e%PL8G4sw4hfPO=)_ASON=|XOK8RWNUd*>l+@EQTkPHt<*YNN!^*o*! literal 0 HcmV?d00001 diff --git a/src/main/java/ExitCommand.class b/src/main/java/ExitCommand.class new file mode 100644 index 0000000000000000000000000000000000000000..e2cb55c46084a4d325578b50c9528c2f4e3169d1 GIT binary patch literal 357 zcmYjNyH3ME5S+Eox!@QGZz&Q*x&$G9z=S4(%A(1mpt~d|IKZ~#2jrt@Xoy6?2k=pd zU4$T4%w7WNgZZ#FbT? zOkA9ds=P3_HttV(xGTl)XZQ^v9OZQ}w^vRq+G~@}?#+`y7ZGnE#|OzCj9Z)?GZS-g zvI4zwz%OEyGN2gS*kKfDmsv3fr*F{zQu!UQKyf2s7kj_*4zrke>Vxn DLc}=X literal 0 HcmV?d00001 diff --git a/src/main/java/FindCommand.class b/src/main/java/FindCommand.class new file mode 100644 index 0000000000000000000000000000000000000000..764aeea3375be772fb999a60ae3db11f981aa05f GIT binary patch literal 1200 zcmaJ>*>Vy=6g^EK1CwDf`z|7hKo;DWOpGR!lva`WKoYC;#SV1B1el>_nneCYzrbg! z6sz*!2l!2v2 zX~+$RfmC{5MGzqcs)iwG46$Q=!m~AQ9%YNtHq0XiKkapf(Nwzdw^0uvf~bO+hAS9m z7|I)F`67=}6|Gatri{b=NEM?PQ!uV!0+S5EUG7v1h9en5hZMv;It=MlKhi6sDUDio z)3$lbh3P7$F{5Bs!yM)rMmnYT`Va?(^Q_*GtxoH&hl!`ShHFSLOw@T*Q;7P4ZMo#-I$t9XEi3Ld#6 zt}!J4%!gr~SXJT8&^fPpUZVWO{rherJje5(&uKnu!buh^tJ-Yn{deD`=>hJx8sZZ7 zH(mZO4~|7i>fJ-^g~;(*t!PN02eHnO*s?dlT_f8i%;7h`2Y+YjMV)y)aE- z=W5(>grndI!$M#0m$jr|lVSeEfF|y{L^0zVd0VB(<<_uSX zHm-j}XxTNS-LO8mVaGeb8K{`0n&yxo*A&%yi)IzYK^cOZ9gm-Zm#y+@x; Oe&gBn~`)MOtht9z=eNA>mn@d@A>Cl*R5D^wg*Q6s2sGM`8BgiyOOvB_@;W!DQW)X`9|9N2IO z^+A+91t!ZGPIWF-MrgR+eIVEuddoo@9fGqYbdw@xKCAUCtYbrA)4>+D38kT7TK15< ztYmF>Db@2rg;67h=_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3oE+E=ULkpLg-;*#U|yiJVqjPzF=)9dNL+cEqIKUVNg zkgY#qiZrRP>~&{NrfZDU5_p<;9k(j*ZY$w+!`h}-d9fCyH<)vrwMuz>H|H&y2Nqth zmgOGit%!I2B6e>vWfY6^mM_Ou{7gU*VWkRzc-FS1J5@A1PkIV|DR6ujz`gud@N0pi zUu?=NvIY_ZyzJUo@<0TPA3FGbozfBZf_*fx4ebJ#eotHAZ)}~L%WnqK2cP^)|0jC~;?;k%|1;A6`6K%+jBdWq zejaB!K4EX*sg-H=ccXuC-(!F8XyotDvwu6OJ+g)Vd)R27`~Y53I}}Q*5lS+tJr+tY zMk(D$YDYq8wu4eOsT~WYXB0}~No^pMMpa6wr1nH84fY16N0Zv|Q0(swYc#hAVm-xJ~a6sI~qj-ZWj-l^!maDW6Pz1QXcC%4ROKUkh;r={1fCSam#)hcq7}9-Xhg0lvbXzzGZ@h2yk3 z!N=su(Eon4eTswh|G%6R1QC3!2fXGVdfn^K!bAt&NNA-kIQI}wXdVae)m^Uyu7q>U z<|d+0T}RZ>L=-IToJ~DsmkN=OMN%Q;vFLr=$tMp*4n?<7ts{Q5f%pzK@Jb!=7`n;9 z2sET|7-xw0Nj~<@a&(?gr3sRM0nhS@brTm+pk@u1xjKU?rb8xlM77ROae!QWhLdC> pB;{~}lvi3vX~*|?RvW&LAFx*$-XF646hEg#2Js903ctaj{{gvZ{Br;R literal 0 HcmV?d00001 diff --git a/src/main/java/Storage.class b/src/main/java/Storage.class new file mode 100644 index 0000000000000000000000000000000000000000..7fa1fab4dc35e9322243f6af24e97d4d068ff502 GIT binary patch literal 2588 zcmaJ@TT>KA6#g1^ca~wet%8h#E(*ASKwQm67nMXV5yLGmLR4}YcLx|*W^iXfP0Zcg z@3*R$$GljTyl5(cDy`%Pr1F%fROKlzc}*%$Ny=!xo?W99TY>8C>C@+&KIc1McklPN zu73yMAU;u1f>H$m4MBtis?Qk9Mt9b*XS>HvpE1*(K0^u1eYmOVb+qO+gjam(L*u-ee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!%LkK`*<-wFWo664uKjq&a*O?cJlld4EOMTi|N4LPex%!L{Z%y&>R>BTX#5Tz3sk5PG{ zZ*_TY7`ax(nYNWI!-v7fh*Pu!AWm6%=GV80=NI#zv=(e?(`AuHB**n;XTq!o1M`5D zG3j~c0v+O$lto&OSc?298J#wNDLuM{FY5B5W!w1x}VF(Q$3ABwn_ktrkYw~~)t8=5KNsUdfhKIBly|n+7 zs+$ux3=N<2PV^c=Ku@aUd?;snp7dh)iYLwnf;Ou=hHrQT{<|sPz#&O!^)d!UwU9dy+5)4&jN>kutlglJ}n-3+mZ zA@(xF9dvV5H6G?Utn#b>83(RCf$ocNCr1B4hP#92a|BgA<^Tp+|Ea#0lzXrbD4N@dvc18P+-PZ8!Z z+A0TITOMH_cUr4%_p}~c!7D*A4=csvzyBzgR1xrekO~3cWmUM$yA+x*PJK?Ghu5RH z%EBg*r$roXr7mM&g*lVZVMXpTM){zO9rie+^E$ET zSnHdNd;=Z0$zMUY7`?DH#^wKtafcWS#K;oEBF0@}EE3}_xXgc^^;xt~syL>29Ao^- zffgn`@dyXG(?TAp^66hOxQuHn%vA~HVFmg8T@6miWizK3jHtomj|QI{dgO2^;IA4L z&k!elo!nFoKH-bcW!)apsD)f@807nip~M820^fVM&#OVW5~I8ytRDvJ$HDqZuzrRw OXcec$m-rgrV(&kSq0S@# literal 0 HcmV?d00001 diff --git a/src/main/java/UnmarkCommand.class b/src/main/java/UnmarkCommand.class new file mode 100644 index 0000000000000000000000000000000000000000..5b746e6cd96fb5ab7cd4d9661e94b731f4dbe7b9 GIT binary patch literal 785 zcmY*XYmd@E6g^WOrKP|Mt`AnU_-tW!@wq-wKS(qosm6pyqJAn+ab)Ri+Op!$G4T(W zD4S@a-~Ca>JG5?MCYiZ+?z!ilxp#j5`Ti5YBeZoWNU2C0$RNw0cEo({`V)riL+P6D) zh=orsv36CQWGKB9JP^^-<=8ujxbSm0#ZZ$-(_hR-USRUj6pP3dZ_N?qPQtp53eHHu zXBjpv=e>LAw)S0r+Ui9C_or=pC}nIJIENZ(kWwWdL&oa9j)NBrn5ffx6IBeF)wLZ7 zqn2F4WffNpT*Wm8WxyGV;XCmmesxTxSur@Kvkf%Rq*@7GDEaI+|M+&WtDe16f_t2AcVP8Ds`*f4HlANwRWJr@Fd33}?q8;vgFV-#TyCaEKy`?u^L}XQC zHL}xfXTaM|QiEDS)9OX;c=p^qNYeDTi>95S)*^$UPOxaG_4FYWGUkg_6RNWKCbV9PU9=o^d}VM z*<7LU8HFFHyee-V;q>zaBpofLNVMYTfu|BgfX4P literal 0 HcmV?d00001 From 58e96c744d87241d1b1e8730381f0761b18880aa Mon Sep 17 00:00:00 2001 From: Trung Bui Date: Mon, 21 Oct 2024 23:40:51 +0800 Subject: [PATCH 21/21] Fix bug in Deadline and reformat code --- src/main/java/AddDeadlineCommand.class | Bin 1554 -> 1554 bytes src/main/java/AddDeadlineCommand.java | 7 +++++-- src/main/java/AddEventCommand.class | Bin 759 -> 759 bytes src/main/java/AddEventCommand.java | 20 ++++++++++++++++++ src/main/java/AddTodoCommand.class | Bin 646 -> 646 bytes src/main/java/AddTodoCommand.java | 6 ++++-- src/main/java/Command.class | Bin 334 -> 334 bytes src/main/java/Command.java | 20 ++++++++++++++++++ src/main/java/Deadline.class | Bin 1932 -> 1932 bytes src/main/java/Deadline.java | 20 ++++++++++++++++++ src/main/java/DeleteCommand.class | Bin 788 -> 788 bytes src/main/java/DeleteCommand.java | 5 +++-- src/main/java/Event.java | 4 ++-- src/main/java/ExitCommand.class | Bin 357 -> 357 bytes src/main/java/ExitCommand.java | 5 +++-- src/main/java/ListCommand.java | 4 ++-- src/main/java/Parser.class | Bin 3001 -> 2993 bytes src/main/java/Parser.java | 28 ++++++++++++++++++++++--- src/main/java/Poirot.class | Bin 1236 -> 1236 bytes src/main/java/Poirot.java | 20 ++++++++++++++++++ src/main/java/PoirotException.class | Bin 230 -> 230 bytes src/main/java/PoirotException.java | 13 ++++++++++-- src/main/java/Storage.class | Bin 2588 -> 2588 bytes src/main/java/Storage.java | 3 +++ src/main/java/Task.class | Bin 636 -> 636 bytes src/main/java/Task.java | 6 ++++++ src/main/java/TaskList.class | Bin 1308 -> 1308 bytes src/main/java/TaskList.java | 8 ++++++- src/main/java/Todo.class | Bin 1202 -> 1202 bytes src/main/java/Todo.java | 4 +++- src/main/java/Ui.class | Bin 3128 -> 3128 bytes src/main/java/Ui.java | 14 +++++++++++-- src/main/java/UnmarkCommand.class | Bin 785 -> 785 bytes src/main/java/UnmarkCommand.java | 20 ++++++++++++++++++ src/main/java/data/duke.txt | 6 +++++- 35 files changed, 191 insertions(+), 22 deletions(-) diff --git a/src/main/java/AddDeadlineCommand.class b/src/main/java/AddDeadlineCommand.class index 2f3dc3ddfd4f18af70e742562a913ae48dfe00d7..692e86ed1e04b50f3d522c40d1732bcfed6ac19c 100644 GIT binary patch delta 79 zcmWN`y%9h#0D#etlPYQaRutkl&HzqMWe`@dO0tMS3?=P*PC4}&k!B?1ND3NCCMv&+ er`16^YI-ySD0D#et=tUhAM?(EI5(9|F$snv?m39$>7)tYQ&t)!q7ol8M~$WrRt7d^EF%XKC&qum%9Mx;h`E1;83|SZ diff --git a/src/main/java/AddDeadlineCommand.java b/src/main/java/AddDeadlineCommand.java index 49a545d51..cb24f3588 100644 --- a/src/main/java/AddDeadlineCommand.java +++ b/src/main/java/AddDeadlineCommand.java @@ -1,6 +1,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; + /** * Command to add a deadline task. */ @@ -8,6 +9,7 @@ public class AddDeadlineCommand extends Command { private String description; private String by; private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"); + /** * Constructs an AddDeadlineCommand with the specified input. * @@ -18,11 +20,12 @@ public AddDeadlineCommand(String input) { this.description = parts[0].trim().substring(9).trim(); this.by = parts[1].trim(); } + /** * Executes the command to add the deadline task to the task list. * - * @param tasks The task list to which the task will be added. - * @param ui The user interface for displaying messages to the user. + * @param tasks The task list to which the task will be added. + * @param ui The user interface for displaying messages to the user. * @param storage The storage for saving tasks to a file. */ @Override diff --git a/src/main/java/AddEventCommand.class b/src/main/java/AddEventCommand.class index 5f5e86d7c9d333b1d4c5fe956c3e660fe20a4656..6de7d0b8e5c6a21cf7d732a6a5572ebe8e29866a 100644 GIT binary patch delta 57 zcmey)`ki${36r280}F!?11Ezp10RD3kQANV$`mfG#30I`%plF6!k`L-h74*9j0|QB J3=B*R<^T)t2J-*_ delta 57 zcmey)`ki${36mfj0}BH?11AFq10RqSX5gCK$`mfm#~{kU&mhepz@W+?$Y97I#K6d4 L#=yY9#9$5p`=th0 diff --git a/src/main/java/AddEventCommand.java b/src/main/java/AddEventCommand.java index 40f929fee..55cc60f41 100644 --- a/src/main/java/AddEventCommand.java +++ b/src/main/java/AddEventCommand.java @@ -1,14 +1,34 @@ +/** + * Represents a command to add a new event to the task list. + * This command creates a new Event task with a description, start time, and end time. + */ public class AddEventCommand extends Command { private String description; private String from; private String to; + /** + * Constructs a new AddEventCommand with the specified event details. + * + * @param description The description of the event. + * @param from The start time/date of the event. + * @param to The end time/date of the event. + */ public AddEventCommand(String description, String from, String to) { this.description = description; this.from = from; this.to = to; } + /** + * Executes the command to add a new event to the task list. + * This method creates a new Event, adds it to the task list, updates the UI, + * and saves the updated task list to storage. + * + * @param tasks The TaskList to which the new event will be added. + * @param ui The Ui object used to display output to the user. + * @param storage The Storage object used to save the updated task list. + */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { Task newTask = new Event(description, from, to); diff --git a/src/main/java/AddTodoCommand.class b/src/main/java/AddTodoCommand.class index 75b669e168fa0e6364c7c6bbb47d3b82569e2063..215b4bf567849815d36f192e3132bddd3ca42829 100644 GIT binary patch delta 49 zcmZo;ZDZXa%*4sVz{0@Gz{$WjS%%49S`x^XVi0DKW{_o&VbBDUj0^@03=B*Rh5(c2 B1cd+q delta 49 zcmZo;ZDZXa%*4sfz{0@8z{$WnS%%49TAYEGL4rY;L6Sk1L5e|>L7IV)!GM8*fr-Ho E0Ft@{cmMzZ diff --git a/src/main/java/AddTodoCommand.java b/src/main/java/AddTodoCommand.java index cfbcbee31..bf922e5db 100644 --- a/src/main/java/AddTodoCommand.java +++ b/src/main/java/AddTodoCommand.java @@ -3,6 +3,7 @@ */ public class AddTodoCommand extends Command { private String description; + /** * Constructs an AddTodoCommand with the specified description. * @@ -11,11 +12,12 @@ public class AddTodoCommand extends Command { public AddTodoCommand(String description) { this.description = description; } + /** * Executes the command to add the todo task to the task list. * - * @param tasks The task list to which the task will be added. - * @param ui The user interface for displaying messages to the user. + * @param tasks The task list to which the task will be added. + * @param ui The user interface for displaying messages to the user. * @param storage The storage for saving tasks to a file. */ @Override diff --git a/src/main/java/Command.class b/src/main/java/Command.class index e120c8d97985ad59d773228ae1c381fcd9f03c18..3b58bf1412a64f67f3a78729688d820b8e773486 100644 GIT binary patch delta 25 gcmX@dbdG5QCnF>4WG+TaZb=441|bFp1||k!07at%ga7~l delta 25 gcmX@dbdG5QCnF={WG+TaZdL|H1|bFp1||k!07QcWYybcN diff --git a/src/main/java/Command.java b/src/main/java/Command.java index a29013e24..7f959fbf4 100644 --- a/src/main/java/Command.java +++ b/src/main/java/Command.java @@ -1,6 +1,26 @@ +/** + * Represents an abstract command in the task management system. + * This class serves as a base for all concrete command implementations. + */ public abstract class Command { + /** + * Executes the command. + * This method should be implemented by all concrete command classes to define + * their specific behavior. + * + * @param tasks The TaskList on which the command operates. + * @param ui The Ui object used to interact with the user. + * @param storage The Storage object used to save and load tasks. + * @throws PoirotException If an error occurs during command execution. + */ public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException; + /** + * Checks if this command should exit the program. + * By default, commands do not exit the program. + * + * @return true if the program should exit after this command, false otherwise. + */ public boolean isExit() { return false; } diff --git a/src/main/java/Deadline.class b/src/main/java/Deadline.class index 830d4fbfdca291f7ed2305e26ae27b94ce730f2c..3169ee89f143afb3ce91e3d58f941b679b3fd4b4 100644 GIT binary patch delta 82 zcmeC-@8RFT%El?ez{()XAiy9tnUBquQGT)yn>(ZC*dGW~^Kc91Pr((ZEvk F901G82bBN- diff --git a/src/main/java/DeleteCommand.java b/src/main/java/DeleteCommand.java index 04aef79d9..17c960324 100644 --- a/src/main/java/DeleteCommand.java +++ b/src/main/java/DeleteCommand.java @@ -3,6 +3,7 @@ */ public class DeleteCommand extends Command { private int index; + /** * Constructs a DeleteCommand with the specified index. * @@ -15,8 +16,8 @@ public DeleteCommand(int index) { /** * Executes the command to delete the specified task from the task list. * - * @param tasks The task list from which the task will be deleted. - * @param ui The user interface for displaying messages to the user. + * @param tasks The task list from which the task will be deleted. + * @param ui The user interface for displaying messages to the user. * @param storage The storage for saving tasks to a file. * @throws PoirotException If the index is out of bounds. */ diff --git a/src/main/java/Event.java b/src/main/java/Event.java index 0e049dc38..d5c4cdda8 100644 --- a/src/main/java/Event.java +++ b/src/main/java/Event.java @@ -11,8 +11,8 @@ public class Event extends Task { * Constructs an Event with the specified description, from, and to time. * * @param description The description of the event. - * @param from The starting time of the event in 'yyyy-MM-dd HHmm' format. - * @param to The ending time of the event in 'yyyy-MM-dd HHmm' format. + * @param from The starting time of the event in 'yyyy-MM-dd HHmm' format. + * @param to The ending time of the event in 'yyyy-MM-dd HHmm' format. */ public Event(String description, String from, String to) { super(description); diff --git a/src/main/java/ExitCommand.class b/src/main/java/ExitCommand.class index e2cb55c46084a4d325578b50c9528c2f4e3169d1..9a437394f80dcb17535e34ff12b9ebb61fb4b052 100644 GIT binary patch delta 19 acmaFL^pt5s6eG6;10#b70|NsSgD3zp5CbUy delta 19 acmaFL^pt5s6eG7d10#b70|NsSgD3zp1p_Dm diff --git a/src/main/java/ExitCommand.java b/src/main/java/ExitCommand.java index ed9d0b986..611ff78f4 100644 --- a/src/main/java/ExitCommand.java +++ b/src/main/java/ExitCommand.java @@ -5,14 +5,15 @@ public class ExitCommand extends Command { /** * Executes the command to exit the application. * - * @param tasks The task list (not used). - * @param ui The user interface for displaying messages to the user. + * @param tasks The task list (not used). + * @param ui The user interface for displaying messages to the user. * @param storage The storage for saving tasks to a file (not used). */ @Override public void execute(TaskList tasks, Ui ui, Storage storage) { ui.showExit(); } + /** * Indicates whether this command is an exit command. * diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java index e6ab13067..e60852602 100644 --- a/src/main/java/ListCommand.java +++ b/src/main/java/ListCommand.java @@ -5,8 +5,8 @@ public class ListCommand extends Command { /** * Executes the command to display the list of tasks. * - * @param tasks The task list to display. - * @param ui The user interface for displaying messages to the user. + * @param tasks The task list to display. + * @param ui The user interface for displaying messages to the user. * @param storage The storage for saving tasks to a file (not used). */ @Override diff --git a/src/main/java/Parser.class b/src/main/java/Parser.class index e2071476acbf1149b995f18b8e27f02775553866..e80c83dbceb2b4b9cc2c33d9d2bd0aa2e51dad5f 100644 GIT binary patch delta 209 zcmWNJ%Sr-a7>1uuifNP*EBOg$iW(vk!ep9q5f~PvRCbaYaFe)ET(!%k=pFo!+b+Rq z)xJ$$Lzg1t#|zKmJ$;)`Gx>F7@oVaQ$iWH@X;~*D9&3^(DbV)E!cZVfqL0=D9ridYAQ}bOS<+1XFp*FH4W*CRj tKc4L*f1-0%xxnL+fGYdcba+jLI#=9s&mB!3Y15#`6K_1zC$_CrJO@vKAj1Fv delta 215 zcmWNJu}Xqr6o#Lp*6(K)BG&Jqlx0eSHKd^UD=KDzIMkH12u|YUreo+Ge1ltb2}U5e zx70Os9ZrHC4jc~e`#k5%UAxO)N96m@`INjLhk(R5lmtP^5t0&NdE!L6MC662^ohxk zGZ_=N3*(s&0y^+$|4s5BVpe!|V{-Kh9z%S*Yj;Ud_qqPQ;FuIHS7b<&=US-@RkF;K zIK{Wcb(rr++kWV$cuSN!65Oj$;D(}JWtu8=RC=by8x01UjA$|8fhld /by "); } - String description = parts[0].trim().substring(9).trim(); + String description = parts[0].trim(); String by = parts[1].trim(); return new AddDeadlineCommand(description + " /by " + by); } catch (ArrayIndexOutOfBoundsException e) { throw new PoirotException("Invalid format for deadline command."); } } - + /** + * Parses the event command input and creates an AddEventCommand object. + * + * @param input The event command input string. + * @return An AddEventCommand object. + * @throws PoirotException If the event format is invalid. + */ private static Command parseEventCommand(String input) throws PoirotException { try { if (!input.contains("/from") || !input.contains("/to")) { diff --git a/src/main/java/Poirot.class b/src/main/java/Poirot.class index 74fd58a02ca57131e92f130c58c07d5aba5b1ac5..da34a1d603aaf50a77b2554cd7f305b84137aaa1 100644 GIT binary patch delta 115 zcmWN@%MHN*007WOn@AJV_IrRe+|cGB7fP LF)%PNF@ysEJ1Gph diff --git a/src/main/java/Poirot.java b/src/main/java/Poirot.java index 9e0354baa..02fd881e9 100644 --- a/src/main/java/Poirot.java +++ b/src/main/java/Poirot.java @@ -1,9 +1,19 @@ +/** + * The main class for the Poirot task management application. + * This class initializes the application, loads saved tasks, and runs the main command loop. + */ public class Poirot { private Storage storage; private TaskList tasks; private Ui ui; + /** + * Constructs a new Poirot application instance. + * Initializes the UI, storage, and task list, and loads any previously saved tasks. + * + * @param filePath The file path for storing and loading tasks. + */ public Poirot(String filePath) { ui = new Ui(); storage = new Storage(filePath); @@ -17,6 +27,10 @@ public Poirot(String filePath) { } } + /** + * Runs the main command loop of the application. + * Continuously reads user input, executes commands, and displays results until an exit command is given. + */ public void run() { ui.showWelcome(); boolean isExit = false; @@ -32,6 +46,12 @@ public void run() { } } + /** + * The main entry point for the Poirot application. + * Creates a new Poirot instance and starts running it. + * + * @param args Command line arguments (not used). + */ public static void main(String[] args) { new Poirot("./data/duke.txt").run(); } diff --git a/src/main/java/PoirotException.class b/src/main/java/PoirotException.class index 8f16cb6441fa67e058c494db2d64b9e3ed5e9237..92234d430a7b3aafb6e25900b62a880e3983a7e2 100644 GIT binary patch delta 22 dcmaFH_>6JFb$%WORt8=MMh0#M1_mYu9sof-1APDh delta 22 dcmaFH_>6JFb$(_BRt6RZMh0#M1_mYu9sod718V>P diff --git a/src/main/java/PoirotException.java b/src/main/java/PoirotException.java index e2a4d4b3c..6817ab4a6 100644 --- a/src/main/java/PoirotException.java +++ b/src/main/java/PoirotException.java @@ -1,5 +1,14 @@ -public class PoirotException extends Exception{ - public PoirotException(String message){ +/** + * Represents a custom exception for the Poirot task management application. + * This exception is used to handle application-specific errors and provide meaningful error messages. + */ +public class PoirotException extends Exception { + /** + * Constructs a new PoirotException with the specified error message. + * + * @param message The detailed error message explaining the reason for the exception. + */ + public PoirotException(String message) { super(message); } } diff --git a/src/main/java/Storage.class b/src/main/java/Storage.class index 7fa1fab4dc35e9322243f6af24e97d4d068ff502..15438ee4e3ab46bf9c77a185ff645dd81a32024b 100644 GIT binary patch delta 204 zcmWN~%PNFn00!XaEB)qI4pVBmENxr?8y7L#xdJO?VJ8>h z0+f}NrLwY`e5?2E?X9Pib+V_IBpuXaNGkvQmfVJiqQtPAlFXP9&%>YRUc|T9L0Zsh^tq)H-yVA$qSlS4a>v|KQeI;AwN*DbP*g|dV*Yf2v?uLNpNVB z9-s#hoSYnmrY7mnfpdm)IKR0wca~po#$$?59bc$d#J49*F1fkRZ?Q^iOVC&wiP z64dZ%kfcwF5m)?>VZ$|Bvh29!pvzzK{Bg&Td$B2sOGzS>CCa13sftfUl03c`%9zn?ZBG6H&k7+k diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java index dd59da6f9..f4a177e7f 100644 --- a/src/main/java/Storage.java +++ b/src/main/java/Storage.java @@ -1,10 +1,12 @@ import java.io.*; import java.util.Scanner; + /** * Handles loading and saving tasks to a file. */ public class Storage { private String filePath; + /** * Constructs a Storage object with the specified file path. * @@ -62,6 +64,7 @@ public Task[] loadTasksFromFile() { return tasks; } + /** * Saves the specified tasks to the file. * diff --git a/src/main/java/Task.class b/src/main/java/Task.class index 48e01303af5083e2731593fe5f9d1a27da0be331..a60f77cd63a572fb09640200c3845128489631a8 100644 GIT binary patch delta 69 zcmeyv@`q)^4n|&H1{MZB22KWkASp2UD5Dmm@Z=ASCX6zZRhca0RT)?r)L0l96c{8K S7=W}Qh-P49Py&)n49Wn;Bne&s delta 69 zcmeyv@`q)^4n|%c1{MZh22KV(AmpEXlu?UOaPkL66Gq9&s!SI0iVUm_N-T^F3Jj7A S3_w~DL^CilC;>?(24w)ln+Z(- diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 4cb4d4dde..8f9059125 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -4,6 +4,7 @@ abstract class Task { protected String description; protected boolean isDone; + /** * Constructs a Task with the specified description. * @@ -13,9 +14,11 @@ public Task(String description) { this.description = description; this.isDone = false; } + public String getDescription() { return description; } + /** * Returns the status icon of the task. * @@ -24,6 +27,7 @@ public String getDescription() { public String getStatusIcon() { return (isDone ? "X" : " "); } + /** * Marks the task as done or not done. * @@ -32,7 +36,9 @@ public String getStatusIcon() { public void setDone(boolean isDone) { this.isDone = isDone; } + public abstract String toString(); + /** * Returns a string representation for saving the task to a file. * diff --git a/src/main/java/TaskList.class b/src/main/java/TaskList.class index 9b205c1141835495606d115b7e3d79b98f704a5e..2776cf037c3d3f0afc227c3963e43defb8ddace5 100644 GIT binary patch delta 121 zcmbQkHHT}%KPFCg1{MYm23`iv$?VKloPrEo3_=Vd48oJWm=i?BfHLAhz665?gCv77 zkZs8zGkHIAxu_}w4}%(m6oV>*0#HteL6gCZL2I%%izTDcoJZ{yJD>$`|>G6wya3mup?*BnM@y2nL^)k VFr{{qo11>+IKKC1gW&=MT>mTV5uN}5 diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 2815eae59..aa9abad5b 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -1,4 +1,5 @@ import java.util.ArrayList; + /** * Represents a list of tasks. */ @@ -26,6 +27,7 @@ public ArrayList findTasks(String keyword) { } return foundTasks; } + /** * Deletes a task from the task list at the specified index. * @@ -38,6 +40,7 @@ public void delete(int index) { tasks[lastIndex - 1] = null; lastIndex--; } + /** * Returns the list of tasks. * @@ -46,6 +49,7 @@ public void delete(int index) { public Task[] getTasks() { return tasks; } + /** * Returns the number of tasks in the task list. * @@ -54,6 +58,7 @@ public Task[] getTasks() { public int getTaskCount() { return lastIndex; } + /** * Returns the task at the specified index. * @@ -63,10 +68,11 @@ public int getTaskCount() { public Task getTask(int index) { return tasks[index]; } + /** * Marks the specified task as done. * - * @param index The index of the task to mark. + * @param index The index of the task to mark. * @param isDone true to mark as done, false otherwise. */ public void markTask(int index, boolean isDone) { diff --git a/src/main/java/Todo.class b/src/main/java/Todo.class index 762beebf1f20189d983474789ab87c146c02c34e..4f529c709593774b570cb3655f7a31d9bf418a70 100644 GIT binary patch delta 19 bcmdnQxruYbHfBcA$=jK28RaK`W!?(_L@Ea8 delta 19 bcmdnQxruYbHfBbV$=jK28D%GbW!?(_L=^_* diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java index e4ab5c972..a260ded37 100644 --- a/src/main/java/Todo.java +++ b/src/main/java/Todo.java @@ -1,7 +1,7 @@ /** * Represents a simple todo task without any specific date or time. */ -public class Todo extends Task{ +public class Todo extends Task { /** * Constructs a Todo with the specified description. * @@ -10,6 +10,7 @@ public class Todo extends Task{ public Todo(String description) { super(description); } + /** * Returns the string representation of the todo task. * @@ -19,6 +20,7 @@ public Todo(String description) { public String toString() { return "[T][" + getStatusIcon() + "] " + description; } + /** * Returns a string representation for saving the todo task to a file. * diff --git a/src/main/java/Ui.class b/src/main/java/Ui.class index cbf3c63deb5d3002fb6ef82e650296a622bd497a..e8bfcbfbdfd92836ca62ced12fed4f0cb7dc7786 100644 GIT binary patch delta 257 zcmWO0&q@MO7zOYXILtU#F_nR9Qf(5Z1`NTm+)0kPtCXaoh2)=>P3lr5ut)fO58DLu zK0QE71zmVH_j1qg-t*l^NBU=L9+L?rwgRuNhyBkl$rRvU4h0G&TtJERasJQD0NCeX;5w{OOr2=CC6W_8?wLM*xD&+tG delta 257 zcmWO0%}N4M7zW^1aGG&Wnm>$9+3d6wK^=A4BL}kAE1C%dN~*?XJb@^VaEK&NN|sErOpck@Oitv> z@U$~1IPz_H@dE9fuM6%J#f|w^jfu!$N@)H|6J<1(_ z&_@P7P7$EY+r0IuN*K$|46F&|g)*hgD09j}Zq-9-$;K7Z Vcw^g&ZSS&GH`)hutmRjA{sH;mDa8N) diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java index 450bf7d18..712af4ae1 100644 --- a/src/main/java/Ui.java +++ b/src/main/java/Ui.java @@ -1,5 +1,6 @@ import java.util.Scanner; import java.util.ArrayList; + /** * Handles the user interface interactions for the task management application. */ @@ -15,6 +16,7 @@ public void showWelcome() { System.out.println("Hello! I'm POIROT\nWhat can I do for you?"); showLine(); } + /** * Displays a goodbye message when exiting the application. */ @@ -28,6 +30,7 @@ public String readCommand() { Scanner scanner = new Scanner(System.in); return scanner.nextLine(); } + /** * Displays an error message to the user. * @@ -38,10 +41,11 @@ public void showError(String message) { System.out.println(message); showLine(); } + /** * Displays a message indicating that a task has been added. * - * @param task The task that was added. + * @param task The task that was added. * @param taskCount The current count of tasks in the list. */ public void showAddedTask(Task task, int taskCount) { @@ -51,10 +55,11 @@ public void showAddedTask(Task task, int taskCount) { System.out.println("Now you have " + taskCount + " tasks in the list."); showLine(); } + /** * Displays a message indicating that a task has been deleted. * - * @param task The task that was deleted. + * @param task The task that was deleted. * @param taskCount The current count of tasks in the list. */ public void showDeletedTask(Task task, int taskCount) { @@ -64,6 +69,7 @@ public void showDeletedTask(Task task, int taskCount) { System.out.println("Now you have " + taskCount + " tasks in the list."); showLine(); } + /** * Displays the list of tasks to the user. * @@ -81,6 +87,7 @@ public void showTaskList(Task[] tasks, int lastIndex) { } showLine(); } + /** * Displays a message indicating that a task has been marked as done. * @@ -93,6 +100,7 @@ public void showMarkTask(Task task) { System.out.println(task.getDescription()); showLine(); } + /** * Displays a message indicating that a task has been unmarked as done. * @@ -105,6 +113,7 @@ public void showUnmarkTask(Task task) { System.out.println(task.getDescription()); showLine(); } + /** * Displays the tasks found that match the keyword. * @@ -116,6 +125,7 @@ public void showFoundTasks(ArrayList tasks) { System.out.println((i + 1) + ". " + tasks.get(i).toString()); } } + public void showMessage(String message) { System.out.println(message); } diff --git a/src/main/java/UnmarkCommand.class b/src/main/java/UnmarkCommand.class index 5b746e6cd96fb5ab7cd4d9661e94b731f4dbe7b9..5a5a0dfb0f74a8982fd86526c926f6d07c28c978 100644 GIT binary patch delta 73 zcmbQpHj!;ZE)yp&0}BHm11AIjt$426+Zq21N!91|-@ diff --git a/src/main/java/UnmarkCommand.java b/src/main/java/UnmarkCommand.java index b8d66d8ab..4f1383111 100644 --- a/src/main/java/UnmarkCommand.java +++ b/src/main/java/UnmarkCommand.java @@ -1,10 +1,30 @@ +/** + * Represents a command to unmark a task as not completed in the Poirot task management system. + * This command changes the status of a task from completed to not completed. + */ public class UnmarkCommand extends Command { private int index; + /** + * Constructs a new UnmarkCommand with the specified task index. + * + * @param index The index of the task to be unmarked (1-based indexing). + */ public UnmarkCommand(int index) { this.index = index; } + /** + * Executes the unmark command. + * This method unmarks the specified task as not completed, updates the UI, + * and saves the changes to storage. + * + * @param tasks The TaskList containing all tasks. + * @param ui The UI object used to display messages to the user. + * @param storage The Storage object used to save tasks. + * @throws PoirotException If the task index is out of bounds. + */ + @Override public void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException { if (index < 1 || index > tasks.getTaskCount()) { diff --git a/src/main/java/data/duke.txt b/src/main/java/data/duke.txt index 6da49ffc3..02a909e61 100644 --- a/src/main/java/data/duke.txt +++ b/src/main/java/data/duke.txt @@ -1,7 +1,11 @@ -T | 1 | sleep +T | 0 | sleep T | 0 | work T | 0 | go to work D | 0 | t | 2025-04-01 1800 E | 0 | party | 2025-04-01 1800 | 2025-04-01 2100 D | 0 | work | 2025-04-01 1800 T | 0 | mini project +D | 0 | uation | 2024-10-31 2359 +T | 0 | go to work +D | 0 | peer evaluation | 2024-10-31 2359 +E | 0 | new party | 2024-11-21 1700 | 2024-11-23 1800