Skip to content

Commit

Permalink
Merge pull request #1 from Cohii2/branch-Level-9
Browse files Browse the repository at this point in the history
Add find function
  • Loading branch information
Cohii2 authored Mar 7, 2024
2 parents d2948f8 + 5c6b134 commit 7830c19
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ bin/

/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT
*.txt
3 changes: 3 additions & 0 deletions src/main/java/duke/MissingParamsException.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public String toString() {
case END:
errorMessage.append("to ");
break;
case TARGET:
errorMessage.append("target ");
break;
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class Parser {
public static final String[] validCommands =
{"list", "mark", "unmark", "todo", "deadline", "event", "bye", "delete"};
{"list", "mark", "unmark", "todo", "deadline", "event", "bye", "delete", "find"};
protected TaskList taskList;

public Parser(TaskList taskList) {
Expand All @@ -30,7 +30,8 @@ public void executeCommand(String command, String argument)

switch (command) {
case "list":
taskList.printList();
String message = "";
taskList.printList(message);
break;
case "mark":
taskList.markTask(argument, true);
Expand All @@ -50,6 +51,9 @@ public void executeCommand(String command, String argument)
case "delete":
taskList.deleteTask(argument);
break;
case "find":
taskList.findTask(argument);
break;
}
}
}
41 changes: 40 additions & 1 deletion src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package duke;

import java.util.ArrayList;
import java.util.List;

import static duke.print.*;
Expand All @@ -17,9 +18,17 @@ public List<Task> getTaskList() {

/**
* Prints list of tasks.
* If message is not empty, prints message in front of list.
*
* @param message Message to be printed before list.
*/
public void printList(){
public void printList(String message){
printLine();

if (!message.isEmpty()) {
System.out.println(message);
}

for(int i = 0; i < taskList.size(); i++){
Task task = taskList.get(i);
System.out.println((i + 1) + "." + task);
Expand Down Expand Up @@ -166,4 +175,34 @@ public void deleteTask(String instruction)
throw new DukeException.IntegerOutOfBoundsException();
}
}

/**
* Finds tasks which descriptions match the target,
* before printing out list of matches.
*
* @param target Target phrase to search for.
*/
public void findTask(String target) throws MissingParamsException {
if (target.isEmpty()) {
List<TaskParams> missingParams = new ArrayList<>();
missingParams.add(TaskParams.TARGET);

throw new MissingParamsException(missingParams);
}

List<Task> matches = new ArrayList<>();

for (Task task : taskList){
if(task.getDescription().contains(target)){
matches.add(task);
}
}

if (matches.isEmpty()){
printMessage("No matches!!");
} else {
new TaskList(matches).printList(
"Here are the matching tasks in your list-gari:");
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/TaskParams.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package duke;

public enum TaskParams {
DESCRIPTION, BY, START, END
DESCRIPTION, BY, START, END, TARGET
}
131 changes: 83 additions & 48 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@ Got it. I've added this task:
Now you have 2 tasks in the list.
______________________________
______________________________
Got it. I've added this task:
[T][ ] Watch CEG Video
Now you have 3 tasks in the list.
______________________________
______________________________
The following parameters are missing:
description
YOU GOTTA SAVE ME AND MY HEART!!
______________________________
______________________________
1.[T][ ] Eat Breakfast
2.[T][ ] Eat Lunch
3.[T][ ] Watch CEG Video
______________________________
______________________________
Got it. I've added this task:
[E][ ] Tutorial (from: 1pm to: 3pm)
Now you have 3 tasks in the list.
Now you have 4 tasks in the list.
______________________________
______________________________
Got it. I've added this task:
[E][ ] Lecture (from: 3pm to: 5pm)
Now you have 4 tasks in the list.
[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
Now you have 5 tasks in the list.
______________________________
______________________________
The following parameters are missing:
Expand Down Expand Up @@ -67,24 +73,25 @@ ______________________________
______________________________
Got it. I've added this task:
[E][ ] Seminar (from: 5pm to: 7pm)
Now you have 5 tasks in the list.
Now you have 6 tasks in the list.
______________________________
______________________________
1.[T][ ] Eat Breakfast
2.[T][ ] Eat Lunch
3.[E][ ] Tutorial (from: 1pm to: 3pm)
4.[E][ ] Lecture (from: 3pm to: 5pm)
5.[E][ ] Seminar (from: 5pm to: 7pm)
3.[T][ ] Watch CEG Video
4.[E][ ] Tutorial (from: 1pm to: 3pm)
5.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
6.[E][ ] Seminar (from: 5pm to: 7pm)
______________________________
______________________________
Got it. I've added this task:
[D][ ] RealizeIt (by: Thursday)
Now you have 6 tasks in the list.
Now you have 7 tasks in the list.
______________________________
______________________________
Got it. I've added this task:
[D][ ] Coursemology (by: Friday)
Now you have 7 tasks in the list.
[D][ ] CEG 1 Coursemology (by: Friday)
Now you have 8 tasks in the list.
______________________________
______________________________
The following parameters are missing:
Expand All @@ -104,69 +111,72 @@ ______________________________
______________________________
Got it. I've added this task:
[D][ ] Teammates (by: Saturday)
Now you have 8 tasks in the list.
Now you have 9 tasks in the list.
______________________________
______________________________
1.[T][ ] Eat Breakfast
2.[T][ ] Eat Lunch
3.[E][ ] Tutorial (from: 1pm to: 3pm)
4.[E][ ] Lecture (from: 3pm to: 5pm)
5.[E][ ] Seminar (from: 5pm to: 7pm)
6.[D][ ] RealizeIt (by: Thursday)
7.[D][ ] Coursemology (by: Friday)
8.[D][ ] Teammates (by: Saturday)
3.[T][ ] Watch CEG Video
4.[E][ ] Tutorial (from: 1pm to: 3pm)
5.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
6.[E][ ] Seminar (from: 5pm to: 7pm)
7.[D][ ] RealizeIt (by: Thursday)
8.[D][ ] CEG 1 Coursemology (by: Friday)
9.[D][ ] Teammates (by: Saturday)
______________________________
______________________________
Nice! I've marked this task as done
[T][X] Eat Breakfast
______________________________
______________________________
Nice! I've marked this task as done
[E][X] Tutorial (from: 1pm to: 3pm)
[T][X] Watch CEG Video
______________________________
______________________________
Nice! I've marked this task as done
[E][X] Seminar (from: 5pm to: 7pm)
[E][X] CEG 1 Lecture (from: 3pm to: 5pm)
______________________________
______________________________
Nice! I've marked this task as done
[D][X] Coursemology (by: Friday)
[D][X] RealizeIt (by: Thursday)
______________________________
______________________________
1.[T][X] Eat Breakfast
2.[T][ ] Eat Lunch
3.[E][X] Tutorial (from: 1pm to: 3pm)
4.[E][ ] Lecture (from: 3pm to: 5pm)
5.[E][X] Seminar (from: 5pm to: 7pm)
6.[D][ ] RealizeIt (by: Thursday)
7.[D][X] Coursemology (by: Friday)
8.[D][ ] Teammates (by: Saturday)
3.[T][X] Watch CEG Video
4.[E][ ] Tutorial (from: 1pm to: 3pm)
5.[E][X] CEG 1 Lecture (from: 3pm to: 5pm)
6.[E][ ] Seminar (from: 5pm to: 7pm)
7.[D][X] RealizeIt (by: Thursday)
8.[D][ ] CEG 1 Coursemology (by: Friday)
9.[D][ ] Teammates (by: Saturday)
______________________________
______________________________
Nice! I've marked this task as undone
[E][ ] Tutorial (from: 1pm to: 3pm)
[T][ ] Watch CEG Video
______________________________
______________________________
Nice! I've marked this task as undone
[E][ ] Lecture (from: 3pm to: 5pm)
[E][ ] Tutorial (from: 1pm to: 3pm)
______________________________
______________________________
Nice! I've marked this task as undone
[E][ ] Seminar (from: 5pm to: 7pm)
[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
______________________________
______________________________
Nice! I've marked this task as undone
[D][ ] RealizeIt (by: Thursday)
[E][ ] Seminar (from: 5pm to: 7pm)
______________________________
______________________________
1.[T][X] Eat Breakfast
2.[T][ ] Eat Lunch
3.[E][ ] Tutorial (from: 1pm to: 3pm)
4.[E][ ] Lecture (from: 3pm to: 5pm)
5.[E][ ] Seminar (from: 5pm to: 7pm)
6.[D][ ] RealizeIt (by: Thursday)
7.[D][X] Coursemology (by: Friday)
8.[D][ ] Teammates (by: Saturday)
3.[T][ ] Watch CEG Video
4.[E][ ] Tutorial (from: 1pm to: 3pm)
5.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
6.[E][ ] Seminar (from: 5pm to: 7pm)
7.[D][X] RealizeIt (by: Thursday)
8.[D][ ] CEG 1 Coursemology (by: Friday)
9.[D][ ] Teammates (by: Saturday)
______________________________
______________________________
Please input an integer!!
Expand All @@ -185,26 +195,50 @@ Task does not exist!!
Invalid instruction ZENBU FAKE!!
______________________________
______________________________
The following parameters are missing:
target
YOU GOTTA SAVE ME AND MY HEART!!
______________________________
______________________________
No matches!!
______________________________
______________________________
Here are the matching tasks in your list-gari:
1.[T][ ] Watch CEG Video
2.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
3.[D][ ] CEG 1 Coursemology (by: Friday)
______________________________
______________________________
Here are the matching tasks in your list-gari:
1.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
2.[D][ ] CEG 1 Coursemology (by: Friday)
______________________________
______________________________
Here are the matching tasks in your list-gari:
1.[T][ ] Watch CEG Video
______________________________
______________________________
1.[T][X] Eat Breakfast
2.[T][ ] Eat Lunch
3.[E][ ] Tutorial (from: 1pm to: 3pm)
4.[E][ ] Lecture (from: 3pm to: 5pm)
5.[E][ ] Seminar (from: 5pm to: 7pm)
6.[D][ ] RealizeIt (by: Thursday)
7.[D][X] Coursemology (by: Friday)
8.[D][ ] Teammates (by: Saturday)
3.[T][ ] Watch CEG Video
4.[E][ ] Tutorial (from: 1pm to: 3pm)
5.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
6.[E][ ] Seminar (from: 5pm to: 7pm)
7.[D][X] RealizeIt (by: Thursday)
8.[D][ ] CEG 1 Coursemology (by: Friday)
9.[D][ ] Teammates (by: Saturday)
______________________________
______________________________
Noted. I've removed this task:
[T][X] Eat Breakfast
______________________________
______________________________
Noted. I've removed this task:
[E][ ] Tutorial (from: 1pm to: 3pm)
[T][ ] Watch CEG Video
______________________________
______________________________
Noted. I've removed this task:
[D][ ] RealizeIt (by: Thursday)
[E][ ] Seminar (from: 5pm to: 7pm)
______________________________
______________________________
Task does not exist!!
Expand All @@ -220,10 +254,11 @@ Invalid instruction ZENBU FAKE!!
______________________________
______________________________
1.[T][ ] Eat Lunch
2.[E][ ] Lecture (from: 3pm to: 5pm)
3.[E][ ] Seminar (from: 5pm to: 7pm)
4.[D][X] Coursemology (by: Friday)
5.[D][ ] Teammates (by: Saturday)
2.[E][ ] Tutorial (from: 1pm to: 3pm)
3.[E][ ] CEG 1 Lecture (from: 3pm to: 5pm)
4.[D][X] RealizeIt (by: Thursday)
5.[D][ ] CEG 1 Coursemology (by: Friday)
6.[D][ ] Teammates (by: Saturday)
______________________________
______________________________
Bye! Hope to see you again soon! MEGANE!!
Expand Down
14 changes: 10 additions & 4 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
todo Eat Breakfast
todo Eat Breakfast
todo Eat Lunch
todo Watch CEG Video
todo
list
event Tutorial /from 1pm /to 3pm
event Lecture /from 3pm /to 5pm
event Seminar
event CEG 1 Lecture /from 3pm /to 5pm
event Seminar
event Seminar /from /to
event Seminar /from 5pm
event Seminar /to 7pm
event /from 5pm /to 7pm
event Seminar /from 5pm /to 7pm
list
deadline RealizeIt /by Thursday
deadline Coursemology /by Friday
deadline CEG 1 Coursemology /by Friday
deadline
deadline Teammates /by
deadline /by Saturday
Expand All @@ -32,6 +33,11 @@ mark string
mark 1000
unmark string
unmark 2000
find
find target that does not exist
find CEG
find CEG 1
find Watch CEG Video
list
delete 1
delete 2
Expand Down

0 comments on commit 7830c19

Please sign in to comment.