Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command and DeleteCommand Feature #26

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/seedu/binbash/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public void addItem(Item item) {
itemList.add(item);
}

public String deleteItem(int index) {
Item tempItem = itemList.remove(index - 1);

String output = "Got it! I've removed the following item:"
+ String.format("\t%s", tempItem);
return output;
}

@Override
public String toString() {
return itemList.toString();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/seedu/binbash/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seedu.binbash.command;

import java.util.regex.Pattern;
import seedu.binbash.ItemList;

public abstract class Command {
public static final String COMMAND_STRING = "command";
public static final Pattern COMMAND_FORMAT =
Pattern.compile("(?<command>\\S+)(?<arguments>.*)");
protected ItemList itemList;

protected Command(ItemList itemList) {
this.itemList = itemList;
}

public abstract String execute();
}
21 changes: 21 additions & 0 deletions src/main/java/seedu/binbash/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package seedu.binbash.command;

import java.util.regex.Pattern;
import seedu.binbash.ItemList;

public class DeleteCommand extends Command {
public static final String COMMAND_STRING = "delete";
public static final Pattern COMMAND_FORMAT =
Pattern.compile("delete\\s(?<index>\\d+)");
protected int index;

public DeleteCommand(ItemList itemList, int index) {
super(itemList);

this.index = index;
}

public String execute() {
return itemList.deleteItem(index);
}
}
Loading