Skip to content

Commit

Permalink
Level-9
Browse files Browse the repository at this point in the history
User can only list all items in task list currently

Add ability for User to find tasks containing a keyword
  • Loading branch information
rgonslayer committed Sep 15, 2022
1 parent 758f2da commit 9322958
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data/taskList.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
T | 0 | read book
D | 0 | return book | 2022-09-20
T | 0 | gym
16 changes: 16 additions & 0 deletions src/main/java/jarvis/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ public void readCommand() throws JarvisException {
}
continue;
}
// if userInput equals find, find tasks which match given string
if (userInput.length() > 4 && userInput.substring(0,4).equals("find")) {
String keyword = userInput.substring((5));
System.out.println("Here are the matching tasks in your list:");
for (int i = 0; i < tasks.getList().size(); i++) {
Task currTask = tasks.getList().get(i);
if (currTask == null) {
break;
}
if (currTask.toString().contains(keyword)) {
System.out.println((i + 1) + ". " + currTask.toString());
}
}
continue;
}

//if userinput equals mark, check which task and mark it
if (userInput.length() > 4 && userInput.substring(0, 4).equals("mark")) {
int toMark = Integer.parseInt(userInput.substring(5)) - 1;
Expand Down

0 comments on commit 9322958

Please sign in to comment.