Skip to content

Commit

Permalink
Fix bug with task numbers when using find
Browse files Browse the repository at this point in the history
  • Loading branch information
NoyaRoeT committed Feb 13, 2023
1 parent 8863d57 commit 09bbb64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test {
}

application {
mainClassName = "duke.Duke"
mainClassName = "duke.Launcher"
}

shadowJar {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/duke/command/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package duke.command;

import java.util.ArrayList;

import duke.DukeResponse;
import duke.MessageGenerator;
import duke.Task;
import duke.TaskList;


/**
* Represents a command that when executed returns tasks found.
*/
Expand All @@ -29,14 +32,21 @@ public DukeResponse execute() {
assert keyword != null;

TaskList tasksOfInterest = new TaskList();

for (Task t : taskList) {
ArrayList<Integer> indexes = new ArrayList<>();
for (int i = 0; i != taskList.size(); ++i) {
Task t = taskList.get(i);
String desc = t.getDescription();
if (desc.contains(keyword)) {
tasksOfInterest.add(t);
indexes.add(i);
}
}

return new DukeResponse(MessageGenerator.genFindTasksMsg(tasksOfInterest.toString()));
String responseMessage = "";
for (int i = 0; i != tasksOfInterest.size(); ++i) {
responseMessage += (indexes.get(i) + 1) + ". " + tasksOfInterest.get(i).toString() + "\n";
}

return new DukeResponse(MessageGenerator.genFindTasksMsg(responseMessage));
}
}

0 comments on commit 09bbb64

Please sign in to comment.