Skip to content

Commit

Permalink
Merge branch 'branch-Level-9'
Browse files Browse the repository at this point in the history
  • Loading branch information
patricktan6 committed Aug 26, 2020
2 parents bc5e327 + 23f113d commit bc0c6e7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
T | ✗ | read book
21 changes: 19 additions & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public static void main(String[] args) throws FileNotFoundException {
} catch (ArrayIndexOutOfBoundsException e) {
throw new MissingDeadlineException();
}
}
}
} catch (ArrayIndexOutOfBoundsException e) {
MissingDescriptionException realError = new MissingDescriptionException("a deadline");
Response msg = new Response(new String[]{String.valueOf(realError)});
System.out.println(msg.getResponse());
} catch (MissingDeadlineException e){
} catch (MissingDeadlineException e) {
Response msg = new Response(new String[]{String.valueOf(e)});
System.out.println(msg.getResponse());
}
Expand All @@ -133,6 +133,23 @@ public static void main(String[] args) throws FileNotFoundException {
Response msg = new Response(new String[]{"Please select the task that you want to delete!"});
System.out.println(msg.getResponse());
}
} else if (test[0].equals("find")) {
try {
if (test.length == 1) {
throw new DukeException();
}
ArrayList<Task> satisfiedTasks = new ArrayList<>();
for (int i = 0; i < lists.size(); i++) {
if (lists.get(i).task.contains(test[1])) {
satisfiedTasks.add(lists.get(i));
}
}
Response msg = new Response(satisfiedTasks.toArray(new Task[0]), Response.Tag.FIND);
System.out.println(msg.getResponse());
} catch (DukeException e) {
Response msg = new Response(new String[]{"Please include the keyword!"});
System.out.println(msg.getResponse());
}
} else {
if (test[0].equals("todo")) {
try {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class DukeException extends Exception {
public DukeException() {
super();
}
}
11 changes: 10 additions & 1 deletion src/main/java/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ enum Tag {
LIST,
ADD,
REMOVE,
NORMAL
NORMAL,
FIND
}
public Task[] tasks;
public String[] texts;
Expand Down Expand Up @@ -72,6 +73,14 @@ public String getResponse() {
+ " "
+ String.format("Now you have %d tasks in the list. \n", numOfTasks);
}
} else if (this.tag == Tag.FIND ) {
for (int i = 0; i < this.tasks.length; i++) {
linesOfText += " "
+ "Here are the matching tasks in your list: \n"
+ " "
+ this.tasks[i]
+ "\n";
}
} else {
for (int i = 0; i < this.texts.length; i++) {
linesOfText += " "
Expand Down

0 comments on commit bc0c6e7

Please sign in to comment.