diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index 7ecaafda17..c66da48805 100644 --- a/src/main/java/seedu/binbash/ItemList.java +++ b/src/main/java/seedu/binbash/ItemList.java @@ -17,8 +17,13 @@ public List getItemList() { /** * Test method */ - public void addItem(Item item) { + public String addItem(String itemName, String itemDescription) { + Item item = new Item(itemName, itemDescription); itemList.add(item); + + String output = "Noted! I have added the following item into your inventory:" + + String.format("\t%s", item); + return output; } public String deleteItem(int index) { diff --git a/src/main/java/seedu/binbash/command/AddCommand.java b/src/main/java/seedu/binbash/command/AddCommand.java new file mode 100644 index 0000000000..94e248c327 --- /dev/null +++ b/src/main/java/seedu/binbash/command/AddCommand.java @@ -0,0 +1,23 @@ +package seedu.binbash.command; + +import java.util.regex.Pattern; +import seedu.binbash.ItemList; + +public class AddCommand extends Command { + public static final String COMMAND_STRING = "add"; + public static final Pattern COMMAND_FORMAT = + Pattern.compile("add\\s/n(?\\s+)\\s/d(?\\s+)"); + private String itemName; + private String itemDescription; + + public AddCommand(ItemList itemList, String itemName, String itemDescription) { + super(itemList); + this.itemName = itemName; + this.itemDescription = itemDescription; + } + + @Override + public String execute() { + return itemList.addItem(itemName, itemDescription); + } +}