forked from nus-tic4001-AY2021S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Impala36/branch-Level-9
Branch level 9
- Loading branch information
Showing
10 changed files
with
143 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package duke.commands; | ||
|
||
import duke.task.TaskList; | ||
import duke.ui.Ui; | ||
|
||
/** | ||
* A command to print out all tasks in the list. | ||
*/ | ||
public class FindCommand extends Command { | ||
public static final String word = "find"; | ||
|
||
public FindCommand(String line, TaskList tasks, Ui ui) { | ||
super(line, tasks, ui); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
String searchWord = line.trim(); | ||
if (tasks.size() == 0) { | ||
ui.printBorderlines("It appears that you have no tasks! Perhaps you should start creating one?"); | ||
return; | ||
} | ||
if (searchWord.isEmpty()) { | ||
ui.printBorderlines("Please type in the 'find <word>' format!"); | ||
return; | ||
} | ||
String matches = "Here are the tasks that matches '" + searchWord + "'!\n"; | ||
boolean hasMatch = false; | ||
for (int i = 0; i < tasks.size(); i++) { | ||
if (tasks.get(i).getDescription().toLowerCase().contains(searchWord)) { | ||
matches = matches.concat((i + 1) + ". " + tasks.get(i).getDescription()) + "\n"; | ||
hasMatch = true; | ||
} | ||
} | ||
if (!hasMatch) { | ||
matches = "It appears that are no matches for '" + searchWord + "'!\n" + | ||
"Perhaps you could try searching another word?"; | ||
} | ||
ui.printBorderlines(matches); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters