From a04064eff878307ee5e61eafd256efbda0f7dd60 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Thu, 14 Mar 2024 10:40:09 +0800 Subject: [PATCH 1/3] Add AddCommand class --- .../seedu/binbash/command/AddCommand.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/seedu/binbash/command/AddCommand.java 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..15fc10d43f --- /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); + } +} \ No newline at end of file From 1d65384e87ba67939838c7a069747f63417b1637 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Thu, 14 Mar 2024 10:40:42 +0800 Subject: [PATCH 2/3] Add addItem method for ItemList class --- src/main/java/seedu/binbash/ItemList.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index 4e1cf42ffc..ebc3bf7cc5 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) { From a16ad5090a3983fb865d8ee974b1650b4d067a66 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Thu, 14 Mar 2024 10:53:34 +0800 Subject: [PATCH 3/3] Add newline to end of AddCommand class --- src/main/java/seedu/binbash/command/AddCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/binbash/command/AddCommand.java b/src/main/java/seedu/binbash/command/AddCommand.java index 15fc10d43f..94e248c327 100644 --- a/src/main/java/seedu/binbash/command/AddCommand.java +++ b/src/main/java/seedu/binbash/command/AddCommand.java @@ -20,4 +20,4 @@ public AddCommand(ItemList itemList, String itemName, String itemDescription) { public String execute() { return itemList.addItem(itemName, itemDescription); } -} \ No newline at end of file +}