Skip to content

Commit

Permalink
Merge branch 'branch-Level-9'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/duke/command/AddCommand.java
#	src/main/java/duke/command/Command.java
#	src/main/java/duke/command/DeleteCommand.java
  • Loading branch information
ChanWeiJie committed Jan 23, 2022
2 parents 54a3489 + 8958073 commit f308db2
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/main/java/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
*/
public class AddCommand extends Command {


/**
* Constructor of AddCommand class.
* @param task task object created from user input.
*/
public AddCommand(Task task) {
super(task, null);
super(task, null, null);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
public abstract class Command{
protected Task task;
protected Integer index;
protected String word;

/**
* Constructor of Command class.
* @param task task object created from user input.
* @param number an indicator to the index of the taskList in TaskList class.
*/
public Command(Task task, Integer number) {
public Command(Task task, Integer number, String word) {
this.task = task;
this.index = number;
this.word = word;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DeleteCommand extends Command {
* @param number an indicator to the index of the taskList in TaskList class.
*/
public DeleteCommand(Integer number) {
super(null, number);
super(null, number, null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ExitCommand extends Command{
* Constructor for ExitCommand class.
*/
public ExitCommand() {
super(null, null);
super(null, null,null);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/duke/command/FindCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package duke.command;

import duke.functionality.TaskList;

public class FindCommand extends Command{
public FindCommand(String word) {
super(null, null, word);
}

@Override
public void execute(TaskList tasks) {
tasks.findWord(super.word);
}

@Override
public boolean isExit() {
return false;
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/command/MarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MarkCommand extends Command {
* @param number an indicator to the index of the taskList in TaskList class.
*/
public MarkCommand(Integer number) {
super(null, number);
super(null, number,null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/PrintCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PrintCommand extends Command{
* Constructor for PrintCommand class.
*/
public PrintCommand() {
super(null, null);
super(null, null, null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class UnmarkCommand extends Command{
* @param number an indicator to the index of the taskList in TaskList class.
*/
public UnmarkCommand(Integer number) {
super(null, number);
super(null, number, null);
}

/**
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/duke/functionality/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
import java.time.format.DateTimeParseException;


import duke.command.Command;
import duke.command.AddCommand;
import duke.command.DeleteCommand;
import duke.command.PrintCommand;
import duke.command.UnmarkCommand;
import duke.command.ExitCommand;
import duke.command.MarkCommand;
import duke.command.*;
import duke.exception.DukeException;
import duke.task.Deadline;
import duke.task.Event;
Expand Down Expand Up @@ -150,6 +144,9 @@ public static Command parse(String input) throws DukeException {
} else if (command.equals("delete")) {
return new DeleteCommand(Integer.parseInt(inputSplit[1]));

} else if(command.equals("find")) {
return new FindCommand(inputSplit[1]);

} else {
throw new InvalidCommandException();
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/duke/functionality/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,16 @@ public void addToList(Task task) {
Storage.updateTextFile();
System.out.println(message + task.toString() + "\nNow you have " + numOfTask + " tasks in the list.");
}

public void findWord(String word) {
String message = "Here are the matching tasks in your list:\n";
System.out.print(message);
for(int i = 0; i < numOfTask; i++) {
Task t = taskList.get(i);
if(t.getDescription().contains(word)) {
String output = i + 1 + "." + t.toString();
System.out.println(output);
}
}
}
}

0 comments on commit f308db2

Please sign in to comment.