From b19b9f32167fc958cf22d10488c2e6bd96978a48 Mon Sep 17 00:00:00 2001 From: Suwei Date: Mon, 2 Mar 2026 15:15:27 +0800 Subject: [PATCH 1/5] Created FindCommand class --- src/main/java/speed/command/FindCommand.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/speed/command/FindCommand.java diff --git a/src/main/java/speed/command/FindCommand.java b/src/main/java/speed/command/FindCommand.java new file mode 100644 index 000000000..c2ecfc9ce --- /dev/null +++ b/src/main/java/speed/command/FindCommand.java @@ -0,0 +1,4 @@ +package speed.command; + +public class FindCommand { +} From af2480210bc4bc89e891ed57462fc1ea2b0f8f87 Mon Sep 17 00:00:00 2001 From: Suwei Date: Mon, 2 Mar 2026 15:23:21 +0800 Subject: [PATCH 2/5] Implemented parseFind --- src/main/java/speed/parser/Parser.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/speed/parser/Parser.java b/src/main/java/speed/parser/Parser.java index cb2eb3a2e..822cb4360 100644 --- a/src/main/java/speed/parser/Parser.java +++ b/src/main/java/speed/parser/Parser.java @@ -5,6 +5,7 @@ import speed.command.DeleteCommand; import speed.command.EventCommand; import speed.command.ExitCommand; +import speed.command.FindCommand; import speed.command.HelpCommand; import speed.command.ListCommand; import speed.command.MarkCommand; @@ -63,6 +64,9 @@ public static Command parseCommand(String input, int totalTaskCount) throws Spee Event task = parseEvent(input); return new EventCommand(task); + } else if (input.equals("find") || input.startsWith("find ") ) { + String keyword = parseFind(input); + return new FindCommand(keyword); } else { throw new SpeedException(Ui.ERROR_UNKNOWN_COMMAND); } @@ -164,4 +168,14 @@ private static Todo parseTodo(String input) throws SpeedException { } return new Todo(description); } + + private static String parseFind(String input) throws SpeedException { + String[] parts = input.split(" ", 2); + String keyword = parts.length < 2 ? "" : parts[1].trim(); + + if (keyword.isEmpty()) { + throw new SpeedException(Ui.ERROR_MISSING_KEYWORD); + } + return keyword; + } } From fa29d38664b98fa6edad2aba3577c407a4bc8704 Mon Sep 17 00:00:00 2001 From: Suwei Date: Mon, 2 Mar 2026 15:24:40 +0800 Subject: [PATCH 3/5] Implemented find method in TaskList using stream. Searches for tasks that contain the matching keyword, case insensitive --- src/main/java/speed/task/TaskList.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/speed/task/TaskList.java b/src/main/java/speed/task/TaskList.java index b2e783508..b67d27463 100644 --- a/src/main/java/speed/task/TaskList.java +++ b/src/main/java/speed/task/TaskList.java @@ -2,6 +2,8 @@ import java.util.ArrayList; +import static java.util.stream.Collectors.toList; + /** * Represents a list of tasks with operations to manage them. */ @@ -98,4 +100,15 @@ public boolean isEmpty() { public ArrayList getTasks() { return tasks; } + + public ArrayList find (String keyword) { + String key = keyword.toLowerCase(); + + ArrayList matchedTasks = (ArrayList) tasks.stream() + .filter(t -> t.getDescription() + .toLowerCase() + .contains(key)) + .collect(toList()); + return matchedTasks; + } } From 5beab87066e6a634c51723bb5e0bd3528cb17f10 Mon Sep 17 00:00:00 2001 From: Suwei Date: Mon, 2 Mar 2026 15:26:11 +0800 Subject: [PATCH 4/5] Implemented printing of the "find list" in ui. Prints all tasks that contains the matching keyword --- src/main/java/speed/ui/Ui.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/speed/ui/Ui.java b/src/main/java/speed/ui/Ui.java index 396e436d3..e073f96f6 100644 --- a/src/main/java/speed/ui/Ui.java +++ b/src/main/java/speed/ui/Ui.java @@ -3,6 +3,7 @@ import speed.task.Task; import speed.task.TaskList; +import java.util.ArrayList; import java.util.Scanner; /** @@ -16,6 +17,9 @@ public class Ui { public static final String ERROR_EMPTY_TODO = "Hold up! You forgot to give a description of the todo!!"; + public static final String ERROR_MISSING_KEYWORD = + "Give me a keyword of what you want me to find bro!"; + public static final String ERROR_NO_TASK_NUMBER = "Please give me the task number as well bro."; @@ -117,7 +121,8 @@ public void printCommandList() { System.out.println("5.mark "); System.out.println("6.unmark "); System.out.println("7.delete "); - System.out.println("8.bye"); + System.out.println("8.find "); + System.out.println("9.bye"); printLine(); } @@ -202,4 +207,21 @@ public void showTaskDeleted(Task task, int remainingTasksCount) { System.out.println("Now you have " + remainingTasksCount + " tasks in the list."); printLine(); } + + public void showFindList(ArrayList matchedTasks) { + if (matchedTasks.isEmpty()) { + printLine(); + System.out.println("No matches found!"); + printLine(); + } else { + printLine(); + System.out.println("Here are the matching tasks in your list:"); + int taskCount = 1; + for (Task task : matchedTasks) { + System.out.println((taskCount++) + "." + task.displayString()); + } + printLine(); + } + + } } From b154448605a77fa06bbb7fbe78de7aaf417072a2 Mon Sep 17 00:00:00 2001 From: Suwei Date: Mon, 2 Mar 2026 15:27:12 +0800 Subject: [PATCH 5/5] Implemented FindCommandClass that executes obtaining an ArrayList of matching tasks to the keyword, and prints it. --- src/main/java/speed/command/FindCommand.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/speed/command/FindCommand.java b/src/main/java/speed/command/FindCommand.java index c2ecfc9ce..c85ee5ed9 100644 --- a/src/main/java/speed/command/FindCommand.java +++ b/src/main/java/speed/command/FindCommand.java @@ -1,4 +1,22 @@ package speed.command; -public class FindCommand { +import speed.exception.SpeedException; +import speed.storage.Storage; +import speed.task.Task; +import speed.task.TaskList; +import speed.ui.Ui; + +import java.util.ArrayList; + +public class FindCommand extends Command { + private final String keyword; + public FindCommand(String keyword) { + this.keyword = keyword; + } + + @Override + public void execute(TaskList tasks, Ui ui, Storage storage) throws SpeedException { + ArrayList matchedTasks = tasks.find(keyword); + ui.showFindList(matchedTasks); + } }