File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed
Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ public static Command parse(String input) throws DukeException {
4040 } else if (inputByParts [0 ].equals ("done" )) {
4141 int taskNumber = Integer .parseInt (inputByParts [1 ]);
4242 return new MarkDoneCommand (taskNumber );
43+ } else if (inputByParts [0 ].equals ("find" )) {
44+ String toFind = inputByParts [1 ];
45+ return new FindCommand (toFind );
4346 } else {
4447 String taskType = inputByParts [0 ];
4548 validateTaskType (taskType );
Original file line number Diff line number Diff line change 33import duke .exception .DukeException ;
44import duke .task .Task ;
55
6+ import java .util .ArrayList ;
67import java .util .List ;
78
89public class TaskList {
@@ -50,6 +51,16 @@ public Task getTask(int taskNumber) throws DukeException {
5051 }
5152 }
5253
54+ public TaskList findTasks (String phrase ) {
55+ List <Task > searchResult = new ArrayList <>();
56+ for (Task task : taskList ) {
57+ if (task .getDescription ().contains (phrase )) {
58+ searchResult .add (task );
59+ }
60+ }
61+ return new TaskList (searchResult );
62+ }
63+
5364 public int getCount () {
5465 return taskList .size ();
5566 }
Original file line number Diff line number Diff line change 1+ package duke .command ;
2+
3+ import duke .Storage ;
4+ import duke .TaskList ;
5+ import duke .Ui ;
6+
7+ public class FindCommand implements Command {
8+ private String toFind ;
9+
10+ public FindCommand (String toFind ) {
11+ this .toFind = toFind ;
12+ }
13+
14+ @ Override
15+ public void execute (TaskList tasks , Ui ui , Storage storage ) {
16+ ui .listTasks (
17+ tasks .findTasks (toFind ));
18+ }
19+
20+ @ Override
21+ public boolean isExit () {
22+ return false ;
23+ }
24+ }
Original file line number Diff line number Diff line change @@ -37,4 +37,8 @@ public String getSaveFormat() {
3737 protected String boxFormat (String symbol ) {
3838 return String .format ("[%s]" , symbol );
3939 }
40+
41+ public String getDescription () {
42+ return description ;
43+ }
4044}
You can’t perform that action at this time.
0 commit comments