From 73cca85928cde0729c7224cb75c42092b2b354e8 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 20:29:48 +0800 Subject: [PATCH 01/12] Add additional attributes to Item class --- src/main/java/seedu/binbash/Item.java | 38 +++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/binbash/Item.java b/src/main/java/seedu/binbash/Item.java index 55c35ab8a6..1832e09a9c 100644 --- a/src/main/java/seedu/binbash/Item.java +++ b/src/main/java/seedu/binbash/Item.java @@ -3,10 +3,21 @@ public class Item { private final String itemName; private final String itemDescription; + private final int itemQuantity; + private final String itemExpirationDate; + private final double itemSalePrice; + private final double itemCostPrice; - public Item(String itemName, String itemDescription) { + + + public Item(String itemName, String itemDescription, int itemQuantity, String itemExpirationDate, + double itemSalePrice, double itemCostPrice) { this.itemName = itemName; this.itemDescription = itemDescription; + this.itemQuantity = itemQuantity; + this.itemExpirationDate = itemExpirationDate; + this.itemSalePrice = itemSalePrice; + this.itemCostPrice = itemCostPrice; } public String getItemName() { @@ -17,8 +28,31 @@ public String getItemDescription() { return itemDescription; } + public int getItemQuantity() { + return itemQuantity; + } + public String getItemExpirationDate() { + return itemExpirationDate; + } + + public double getItemSalePrice() { + return itemSalePrice; + } + + public double getItemCostPrice() { + return itemCostPrice; + } + @Override public String toString() { - return itemName + ": " + itemDescription; + return String.format( + "%s\n \tdescription: %s\n \tquantity: %d\n \texpiry date: %s\n \tsale price: $%.2f\n \tcost price: $%.2f", + itemName, + itemDescription, + itemQuantity, + itemExpirationDate, + itemSalePrice, + itemCostPrice + ); } } From 86833da76264f873a5f03e3d122f50c75e6d6274 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 20:30:37 +0800 Subject: [PATCH 02/12] Modify addItem method to take in additional parameters --- src/main/java/seedu/binbash/ItemList.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index dd5bbff254..d07bc104af 100644 --- a/src/main/java/seedu/binbash/ItemList.java +++ b/src/main/java/seedu/binbash/ItemList.java @@ -23,13 +23,14 @@ public int getItemCount() { return itemList.size(); } - public String addItem(String itemName, String itemDescription) { - Item item = new Item(itemName, itemDescription); + public String addItem(String itemName, String itemDescription, int itemQuantity, String itemExpirationDate, + double itemSalePrice, double itemCostPrice) { + Item item = new Item(itemName, itemDescription, itemQuantity, itemExpirationDate, itemSalePrice, itemCostPrice); itemList.add(item); - String output = "Noted! I have added the following item into your inventory:" - + String.format("\t%s", item); + String output = "Noted! I have added the following item into your inventory:\n" + + "\n" + item; return output; } From 037d3400755d94a53925ddd8622741a8637fc9d1 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 20:36:29 +0800 Subject: [PATCH 03/12] Modify parseAddCommand to handle additional parameters --- src/main/java/seedu/binbash/Parser.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/binbash/Parser.java b/src/main/java/seedu/binbash/Parser.java index d406419cb5..4e14a85df7 100644 --- a/src/main/java/seedu/binbash/Parser.java +++ b/src/main/java/seedu/binbash/Parser.java @@ -50,7 +50,13 @@ private Command parseAddCommand(String userInput) { if (matcher.matches()) { String itemName = matcher.group("itemName"); String itemDescription = matcher.group("itemDescription"); - return new AddCommand(itemList, itemName, itemDescription); + int itemQuantity = Integer.parseInt(matcher.group("itemQuantity")); + String itemExpirationDate = matcher.group("itemExpirationDate"); + double itemSalePrice = Double.parseDouble(matcher.group("itemSalePrice")); + double itemCostPrice = Double.parseDouble(matcher.group("itemCostPrice")); + + return new AddCommand(itemList, itemName, itemDescription, itemQuantity, itemExpirationDate, itemSalePrice, + itemCostPrice); } else { return null; } From abfc98dc09ca542af82dd93e7f00d18c8c3ae668 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 20:37:05 +0800 Subject: [PATCH 04/12] Modify AddCommand class to include new parameters --- .../java/seedu/binbash/command/AddCommand.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/binbash/command/AddCommand.java b/src/main/java/seedu/binbash/command/AddCommand.java index 70f4348f38..daf7b1271e 100644 --- a/src/main/java/seedu/binbash/command/AddCommand.java +++ b/src/main/java/seedu/binbash/command/AddCommand.java @@ -7,21 +7,32 @@ public class AddCommand extends Command { public static final String COMMAND_STRING = "add"; public static final Pattern COMMAND_FORMAT = - Pattern.compile("add\\s+n/(?.+?)\\s+d/(?.+)"); + Pattern.compile("add\\s+n/(?.+?)\\s+d/(?.+)\\s+q/(?.+)\\s" + + "+e/(?.+)+s/(?.+)+c/(?.+)"); private String itemName; private String itemDescription; + private int itemQuantity; + private String itemExpirationDate; + private double itemSalePrice; + private double itemCostPrice; - public AddCommand(ItemList itemList, String itemName, String itemDescription) { + public AddCommand(ItemList itemList, String itemName, String itemDescription, int itemQuantity, + String itemExpirationDate, double itemSalePrice, double itemCostPrice) { super(itemList); this.itemName = itemName; this.itemDescription = itemDescription; + this.itemQuantity = itemQuantity; + this.itemExpirationDate = itemExpirationDate; + this.itemSalePrice = itemSalePrice; + this.itemCostPrice = itemCostPrice; } @Override public String execute() { - return itemList.addItem(itemName, itemDescription); + return itemList.addItem(itemName, itemDescription, itemQuantity, itemExpirationDate, + itemSalePrice, itemCostPrice); } } From 939776d0f2acc4680dbc7b162ffb7792e57716d3 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 20:37:25 +0800 Subject: [PATCH 05/12] Add new parameters to AddCommandTest test case --- src/test/java/seedu/binbash/command/AddCommandTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/seedu/binbash/command/AddCommandTest.java b/src/test/java/seedu/binbash/command/AddCommandTest.java index 0ad9d6bcb8..2420c23e57 100644 --- a/src/test/java/seedu/binbash/command/AddCommandTest.java +++ b/src/test/java/seedu/binbash/command/AddCommandTest.java @@ -10,7 +10,8 @@ public class AddCommandTest { @Test void execute_item_oneItemInItemList() { ItemList itemList = new ItemList(); - AddCommand addCommand = new AddCommand(itemList, "testItem", "A test item"); + AddCommand addCommand = new AddCommand(itemList, "testItem", "1", 2, + "3", 4.00, 5.00); addCommand.execute(); assertEquals(1, itemList.getItemCount()); From 6758383f014af5995de6abb6effdfcc37e0cd903 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 21:05:37 +0800 Subject: [PATCH 06/12] Add new line after each item in inventory list --- src/main/java/seedu/binbash/ItemList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index d07bc104af..12330af93c 100644 --- a/src/main/java/seedu/binbash/ItemList.java +++ b/src/main/java/seedu/binbash/ItemList.java @@ -70,7 +70,7 @@ public String printList(List itemList) { String output = ""; for (Item item: itemList) { - output += item.toString() + System.lineSeparator(); + output += item.toString() + System.lineSeparator() + System.lineSeparator(); } return output; From a6136fdbc81321f7640add02c87c7ca345b260fc Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 21:07:44 +0800 Subject: [PATCH 07/12] Modify tests to include new parameters --- src/test/java/seedu/binbash/ItemListTest.java | 21 +++++++++++++------ .../seedu/binbash/command/AddCommandTest.java | 2 +- .../binbash/command/ListCommandTest.java | 6 ++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/test/java/seedu/binbash/ItemListTest.java b/src/test/java/seedu/binbash/ItemListTest.java index 33698c2a23..cfd2d60833 100644 --- a/src/test/java/seedu/binbash/ItemListTest.java +++ b/src/test/java/seedu/binbash/ItemListTest.java @@ -9,7 +9,8 @@ class ItemListTest { @Test void deleteItem_oneItemInItemList_noItemInItemList() { ItemList itemList = new ItemList(); - itemList.addItem("testItem", "A test item"); + itemList.addItem("testItem", "A test item", 2, + "3", 4.00, 5.00); itemList.deleteItem(1); @@ -20,27 +21,35 @@ void deleteItem_oneItemInItemList_noItemInItemList() { void addItem_noItemInItemList_oneItemInItemList() { ItemList itemList = new ItemList(); - itemList.addItem("testItem", "A test item"); + itemList.addItem("testItem", "A test item", 2, + "3", 4.00, 5.00); assertEquals(1, itemList.getItemCount()); } @Test - void addItem_itemNameAndDescription_correctItemNameAndDescription() { + void addItem_itemInputs_correctItemParameters() { ItemList itemList = new ItemList(); - itemList.addItem("testItem", "A test item"); + itemList.addItem("testItem", "A test item", 2, + "3", 4.00, 5.00); Item item = itemList.getItemList().get(0); assertEquals(item.getItemName(), "testItem"); assertEquals(item.getItemDescription(), "A test item"); + assertEquals(item.getItemQuantity(), 2); + assertEquals(item.getItemExpirationDate(), "3"); + assertEquals(item.getItemSalePrice(), 4.00); + assertEquals(item.getItemCostPrice(), 5.00); } @Test void printList_twoItemsInItemList_correctPrintFormatForBothItems() { ItemList itemList = new ItemList(); - itemList.addItem("testItem", "1"); - itemList.addItem("testItem", "2"); + itemList.addItem("testItem1", "Test item 1", 2, + "3", 4.00, 5.00); + itemList.addItem("testItem2", "Test item 2", 6, + "7", 8.00, 9.00); String actualOutput = itemList.printList(itemList.getItemList()); diff --git a/src/test/java/seedu/binbash/command/AddCommandTest.java b/src/test/java/seedu/binbash/command/AddCommandTest.java index 2420c23e57..8eaf1ed53c 100644 --- a/src/test/java/seedu/binbash/command/AddCommandTest.java +++ b/src/test/java/seedu/binbash/command/AddCommandTest.java @@ -10,7 +10,7 @@ public class AddCommandTest { @Test void execute_item_oneItemInItemList() { ItemList itemList = new ItemList(); - AddCommand addCommand = new AddCommand(itemList, "testItem", "1", 2, + AddCommand addCommand = new AddCommand(itemList, "testItem", "A test item", 2, "3", 4.00, 5.00); addCommand.execute(); diff --git a/src/test/java/seedu/binbash/command/ListCommandTest.java b/src/test/java/seedu/binbash/command/ListCommandTest.java index ce5dcb5cff..4a4b9c0fb4 100644 --- a/src/test/java/seedu/binbash/command/ListCommandTest.java +++ b/src/test/java/seedu/binbash/command/ListCommandTest.java @@ -11,8 +11,10 @@ class ListCommandTest { void execute_listCommandWithTwoItemsInItemList_correctPrintFormatForBothItems() { ItemList itemList = new ItemList(); - itemList.addItem("testItem", "1"); - itemList.addItem("testItem", "2"); + itemList.addItem("testItem1", "Test item 1", 2, + "3", 4.00, 5.00); + itemList.addItem("testItem2", "Test item 2", 6, + "7", 8.00, 9.00); ListCommand listCommand = new ListCommand(itemList); From 86262572db69f3360b890c52c1acf29979447f2a Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 21:08:13 +0800 Subject: [PATCH 08/12] Modify expected output strings for list tests --- src/test/java/seedu/binbash/ItemListTest.java | 15 +++++++++++++-- .../seedu/binbash/command/ListCommandTest.java | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/test/java/seedu/binbash/ItemListTest.java b/src/test/java/seedu/binbash/ItemListTest.java index cfd2d60833..e7fc67d25a 100644 --- a/src/test/java/seedu/binbash/ItemListTest.java +++ b/src/test/java/seedu/binbash/ItemListTest.java @@ -53,8 +53,19 @@ void printList_twoItemsInItemList_correctPrintFormatForBothItems() { String actualOutput = itemList.printList(itemList.getItemList()); - String expectedOutput = "testItem: 1" + System.lineSeparator() + - "testItem: 2" + System.lineSeparator(); + String expectedOutput = "testItem1" + System.lineSeparator() + + "\tdescription: Test item 1" + System.lineSeparator() + + "\tquantity: 2" + System.lineSeparator() + + "\texpiry date: 3" + System.lineSeparator() + + "\tsale price: $4.00" + System.lineSeparator() + + "\tcost price: $5.00" + System.lineSeparator() + + System.lineSeparator() + + "testItem2" + System.lineSeparator() + + "\tdescription: Test item 2" + System.lineSeparator() + + "\tquantity: 6" + System.lineSeparator() + + "\texpiry date: 7" + System.lineSeparator() + + "\tsale price: $8.00" + System.lineSeparator() + + "\tcost price: $9.00" + System.lineSeparator(); assertEquals(expectedOutput, actualOutput); } diff --git a/src/test/java/seedu/binbash/command/ListCommandTest.java b/src/test/java/seedu/binbash/command/ListCommandTest.java index 4a4b9c0fb4..6339bcb9aa 100644 --- a/src/test/java/seedu/binbash/command/ListCommandTest.java +++ b/src/test/java/seedu/binbash/command/ListCommandTest.java @@ -20,8 +20,20 @@ void execute_listCommandWithTwoItemsInItemList_correctPrintFormatForBothItems() String actualOutput = listCommand.execute(); - String expectedOutput = "testItem: 1" + System.lineSeparator() + - "testItem: 2" + System.lineSeparator(); + String expectedOutput = "testItem1" + System.lineSeparator() + + "\tdescription: Test item 1" + System.lineSeparator() + + "\tquantity: 2" + System.lineSeparator() + + "\texpiry date: 3" + System.lineSeparator() + + "\tsale price: $4.00" + System.lineSeparator() + + "\tcost price: $5.00" + System.lineSeparator() + + System.lineSeparator() + + "testItem2" + System.lineSeparator() + + "\tdescription: Test item 2" + System.lineSeparator() + + "\tquantity: 6" + System.lineSeparator() + + "\texpiry date: 7" + System.lineSeparator() + + "\tsale price: $8.00" + System.lineSeparator() + + "\tcost price: $9.00" + System.lineSeparator(); + assertEquals(expectedOutput, actualOutput); } From cdc1af81786be357638b5f8ccfae526daec5f1a8 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 21:14:49 +0800 Subject: [PATCH 09/12] Add line separator to expected test outputs --- src/test/java/seedu/binbash/ItemListTest.java | 3 ++- src/test/java/seedu/binbash/command/ListCommandTest.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/seedu/binbash/ItemListTest.java b/src/test/java/seedu/binbash/ItemListTest.java index e7fc67d25a..a610deda1e 100644 --- a/src/test/java/seedu/binbash/ItemListTest.java +++ b/src/test/java/seedu/binbash/ItemListTest.java @@ -65,7 +65,8 @@ void printList_twoItemsInItemList_correctPrintFormatForBothItems() { "\tquantity: 6" + System.lineSeparator() + "\texpiry date: 7" + System.lineSeparator() + "\tsale price: $8.00" + System.lineSeparator() + - "\tcost price: $9.00" + System.lineSeparator(); + "\tcost price: $9.00" + System.lineSeparator() + + System.lineSeparator(); assertEquals(expectedOutput, actualOutput); } diff --git a/src/test/java/seedu/binbash/command/ListCommandTest.java b/src/test/java/seedu/binbash/command/ListCommandTest.java index 6339bcb9aa..6343413ef9 100644 --- a/src/test/java/seedu/binbash/command/ListCommandTest.java +++ b/src/test/java/seedu/binbash/command/ListCommandTest.java @@ -32,8 +32,8 @@ void execute_listCommandWithTwoItemsInItemList_correctPrintFormatForBothItems() "\tquantity: 6" + System.lineSeparator() + "\texpiry date: 7" + System.lineSeparator() + "\tsale price: $8.00" + System.lineSeparator() + - "\tcost price: $9.00" + System.lineSeparator(); - + "\tcost price: $9.00" + System.lineSeparator() + + System.lineSeparator(); assertEquals(expectedOutput, actualOutput); } From a271ddc65fbfac8b8a5e313d421d9620f6d3ab67 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 21:15:55 +0800 Subject: [PATCH 10/12] Modify length of code to comply with Java coding standards --- src/main/java/seedu/binbash/Item.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/binbash/Item.java b/src/main/java/seedu/binbash/Item.java index 1832e09a9c..1a800d695e 100644 --- a/src/main/java/seedu/binbash/Item.java +++ b/src/main/java/seedu/binbash/Item.java @@ -46,7 +46,8 @@ public double getItemCostPrice() { @Override public String toString() { return String.format( - "%s\n \tdescription: %s\n \tquantity: %d\n \texpiry date: %s\n \tsale price: $%.2f\n \tcost price: $%.2f", + "%s\n \tdescription: %s\n \tquantity: %d\n \texpiry date: %s\n \tsale price: $%.2f\n " + + "\tcost price: $%.2f", itemName, itemDescription, itemQuantity, From 909ecb6fc71a6f28e0c7f5165a8aa50228e486f5 Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 21:41:53 +0800 Subject: [PATCH 11/12] Modify new line generator in toString method --- src/main/java/seedu/binbash/Item.java | 7 +++++-- src/test/java/seedu/binbash/ItemListTest.java | 1 + src/test/java/seedu/binbash/command/ListCommandTest.java | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/binbash/Item.java b/src/main/java/seedu/binbash/Item.java index 1a800d695e..a10c0deeb4 100644 --- a/src/main/java/seedu/binbash/Item.java +++ b/src/main/java/seedu/binbash/Item.java @@ -45,8 +45,11 @@ public double getItemCostPrice() { @Override public String toString() { - return String.format( - "%s\n \tdescription: %s\n \tquantity: %d\n \texpiry date: %s\n \tsale price: $%.2f\n " + + return String.format("%s" + System.lineSeparator() + + "\tdescription: %s" + System.lineSeparator() + + "\tquantity: %d" + System.lineSeparator() + + "\texpiry date: %s" + System.lineSeparator() + + "\tsale price: $%.2f" + System.lineSeparator() + "\tcost price: $%.2f", itemName, itemDescription, diff --git a/src/test/java/seedu/binbash/ItemListTest.java b/src/test/java/seedu/binbash/ItemListTest.java index a610deda1e..695ec90530 100644 --- a/src/test/java/seedu/binbash/ItemListTest.java +++ b/src/test/java/seedu/binbash/ItemListTest.java @@ -66,6 +66,7 @@ void printList_twoItemsInItemList_correctPrintFormatForBothItems() { "\texpiry date: 7" + System.lineSeparator() + "\tsale price: $8.00" + System.lineSeparator() + "\tcost price: $9.00" + System.lineSeparator() + + System.lineSeparator() + System.lineSeparator(); assertEquals(expectedOutput, actualOutput); diff --git a/src/test/java/seedu/binbash/command/ListCommandTest.java b/src/test/java/seedu/binbash/command/ListCommandTest.java index 6343413ef9..fc7814b8e1 100644 --- a/src/test/java/seedu/binbash/command/ListCommandTest.java +++ b/src/test/java/seedu/binbash/command/ListCommandTest.java @@ -33,6 +33,7 @@ void execute_listCommandWithTwoItemsInItemList_correctPrintFormatForBothItems() "\texpiry date: 7" + System.lineSeparator() + "\tsale price: $8.00" + System.lineSeparator() + "\tcost price: $9.00" + System.lineSeparator() + + System.lineSeparator() + System.lineSeparator(); assertEquals(expectedOutput, actualOutput); From a0dfa4faea7b7cb26d8abbd508bf91fdd7ad43af Mon Sep 17 00:00:00 2001 From: imanamirshah Date: Sun, 17 Mar 2024 21:45:59 +0800 Subject: [PATCH 12/12] Remove additional new line in expected output --- src/test/java/seedu/binbash/ItemListTest.java | 1 - src/test/java/seedu/binbash/command/ListCommandTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/test/java/seedu/binbash/ItemListTest.java b/src/test/java/seedu/binbash/ItemListTest.java index 695ec90530..a610deda1e 100644 --- a/src/test/java/seedu/binbash/ItemListTest.java +++ b/src/test/java/seedu/binbash/ItemListTest.java @@ -66,7 +66,6 @@ void printList_twoItemsInItemList_correctPrintFormatForBothItems() { "\texpiry date: 7" + System.lineSeparator() + "\tsale price: $8.00" + System.lineSeparator() + "\tcost price: $9.00" + System.lineSeparator() + - System.lineSeparator() + System.lineSeparator(); assertEquals(expectedOutput, actualOutput); diff --git a/src/test/java/seedu/binbash/command/ListCommandTest.java b/src/test/java/seedu/binbash/command/ListCommandTest.java index fc7814b8e1..6343413ef9 100644 --- a/src/test/java/seedu/binbash/command/ListCommandTest.java +++ b/src/test/java/seedu/binbash/command/ListCommandTest.java @@ -33,7 +33,6 @@ void execute_listCommandWithTwoItemsInItemList_correctPrintFormatForBothItems() "\texpiry date: 7" + System.lineSeparator() + "\tsale price: $8.00" + System.lineSeparator() + "\tcost price: $9.00" + System.lineSeparator() + - System.lineSeparator() + System.lineSeparator(); assertEquals(expectedOutput, actualOutput);