Skip to content

Commit

Permalink
Resolved merge conflict between branch-A-CodingStandard and branch-le…
Browse files Browse the repository at this point in the history
…vel-9
  • Loading branch information
dreammac3816547290 committed Sep 16, 2022
2 parents 5f3bbf9 + 2d794ce commit 337e3d9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/duke/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public void run(Duke duke) {
default:
task = new Task(""); // error
}
duke.add(task);
duke.addTask(task);
}
}
13 changes: 12 additions & 1 deletion src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void start() {
*
* @param task Task to add.
*/
public void add(Task task) { // error if description is empty
public void addTask(Task task) { // error if description is empty
tasks.add(task);
ui.addTask(task);
ui.infoCount(tasks.size());
Expand Down Expand Up @@ -75,6 +75,17 @@ public void deleteTask(int index) {
ui.infoCount(tasks.size());
}

/**
* Print all tasks that matches the keyword to the UI.
*
* @param keyword Keyword to match.
*/
public void findTasks(String keyword) {
TaskList matches = (TaskList) tasks.clone();
matches.removeIf(task -> !task.toString().toLowerCase().contains(keyword.toLowerCase()));
ui.findTasks(matches);
}

/**
* Exit the Duke Chatterbot.
*/
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/duke/FindCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package duke;

/**
* Represents a Command to find tasks in Duke that matches a certain keyword.
*/
public class FindCommand extends Command {
protected String keyword;

/**
* Constructor of FindCommand with keyword to match.
*
* @param keyword Keyword to match.
*/
public FindCommand(String keyword) {
this.keyword = keyword;
}

/**
* Run the FindCommand, print all tasks in Duke that matches the keyword to the UI.
*
* @param duke Duke instance to run the AddCommand at.
*/
@Override
public void run(Duke duke) {
duke.findTasks(keyword);
}
}
4 changes: 3 additions & 1 deletion src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public static Command parseInput(String input) {
return new MarkCommand(Integer.parseInt(inputParts[1]) - 1, true);
case "unmark":
return new MarkCommand(Integer.parseInt(inputParts[1]) - 1, false);
case "find":
return new FindCommand(inputParts[1]);
case "todo":
return new AddCommand('T', inputParts[1]);
case "deadline":
Expand All @@ -57,7 +59,7 @@ public static Command parseInput(String input) {
return new DeleteCommand(Integer.parseInt(inputParts[1]) - 1);
default:
return new ExitCommand();
// throw new duke.DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
// throw new duke.DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ public void deleteTask(Task task) {
print(task.toString());
}

/**
* Print all matching tasks to the UI.
*
* @param tasks List of matching tasks.
*/
public void findTasks(TaskList tasks) {
print("Here are the matching tasks in your list:");
for (int i = 0; i < tasks.size(); i++) {
print((i + 1) + ". " + tasks.get(i));
}
}

/**
* Prints a goodbye message and closes the UI.
*/
Expand Down

0 comments on commit 337e3d9

Please sign in to comment.