Skip to content

Commit

Permalink
Updated README and FindCommand when no task is found
Browse files Browse the repository at this point in the history
  • Loading branch information
anqi20 committed Oct 1, 2020
1 parent ab519d3 commit 7dad94a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 5 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ Prerequisites: Java 11.
3. Go into the directory containing the ip.jar file.
1. Use `cd` to enter the directory.
2. Use `ls` or `dir` to list all the files in the specific directory.
4. Type `java -jar ip.jar` into the command prompt.
5. Enter to start the program.
4. Type `chcp 65001` into the command prompt.
5. Press enter at the command prompt.
6. Type `java -Dfile.encoding=UTF-8 -jar ip.jar` into the command prompt.
7. Press enter to start the program.

> Note: If the status icons appear as ? instead of ✓ or ✘, change the font of the command promp to NSimSun.
```
Hello from
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/duke/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,26 @@ public FindCommand(String userCommand) {
*/
@Override
public void execute(TaskList taskList, Storage storage) {
int numberOfTasks = taskList.getSize();
int numberOfTasks = 0;
ArrayList<Task> currentList = new ArrayList<>();

try {
String userCommandDescription = userCommand.substring(Constants.LENGTH_OF_FIND+1).trim();

for(int i=0; i<numberOfTasks; i++) {
for(int i=0; i<taskList.getSize(); i++) {
Task task = taskList.get(i);

if(task.getDescription().contains(userCommandDescription)) {
currentList.add(task);
numberOfTasks++;
}
}
Ui.printFind(currentList);

if(numberOfTasks == 0) {
Ui.printFindNothing();
} else {
Ui.printFind(currentList);
}

} catch (StringIndexOutOfBoundsException e) {
Ui.printFormattingInvalid(); //Wrong formatting was given
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/duke/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,28 @@ public static void printHelp() {
printDashLine();
}

/**
* Prints the message when the user finds certain keywords.
* Prints the list of tasks which contains the keywords.
*
* @param list of tasks which contains the keywords.
*/
public static void printFind(ArrayList<Task> list) {
printDashLine();
System.out.println("Here are the matching tasks in your list: ");
printEntireList(list);
printDashLine();
}

/**
* Prints the message when all the tasks do not contain the keywords.
*/
public static void printFindNothing() {
printDashLine();
System.out.println("There is no matching task in your list. ");
printDashLine();
}

/**
* Prints the error message when there is problems with the formatting.
*/
Expand Down

0 comments on commit 7dad94a

Please sign in to comment.