diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index 30ff109fd5..4e1cf42ffc 100644 --- a/src/main/java/seedu/binbash/ItemList.java +++ b/src/main/java/seedu/binbash/ItemList.java @@ -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(); diff --git a/src/main/java/seedu/binbash/command/Command.java b/src/main/java/seedu/binbash/command/Command.java new file mode 100644 index 0000000000..863bd18a14 --- /dev/null +++ b/src/main/java/seedu/binbash/command/Command.java @@ -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("(?\\S+)(?.*)"); + protected ItemList itemList; + + protected Command(ItemList itemList) { + this.itemList = itemList; + } + + public abstract String execute(); +} diff --git a/src/main/java/seedu/binbash/command/DeleteCommand.java b/src/main/java/seedu/binbash/command/DeleteCommand.java new file mode 100644 index 0000000000..351456c11e --- /dev/null +++ b/src/main/java/seedu/binbash/command/DeleteCommand.java @@ -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(?\\d+)"); + protected int index; + + public DeleteCommand(ItemList itemList, int index) { + super(itemList); + + this.index = index; + } + + public String execute() { + return itemList.deleteItem(index); + } +}