From 16e1110885e1c180ba3a9b9da6521384fab4f905 Mon Sep 17 00:00:00 2001 From: YHWong20 Date: Mon, 11 Mar 2024 15:53:02 +0800 Subject: [PATCH 01/14] Update package names --- src/main/java/seedu/{duke => binbash}/Duke.java | 2 +- src/test/java/seedu/{duke => binbash}/DukeTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/seedu/{duke => binbash}/Duke.java (96%) rename src/test/java/seedu/{duke => binbash}/DukeTest.java (89%) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/binbash/Duke.java similarity index 96% rename from src/main/java/seedu/duke/Duke.java rename to src/main/java/seedu/binbash/Duke.java index 5c74e68d59..a00833698e 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/binbash/Duke.java @@ -1,4 +1,4 @@ -package seedu.duke; +package seedu.binbash; import java.util.Scanner; diff --git a/src/test/java/seedu/duke/DukeTest.java b/src/test/java/seedu/binbash/DukeTest.java similarity index 89% rename from src/test/java/seedu/duke/DukeTest.java rename to src/test/java/seedu/binbash/DukeTest.java index 2dda5fd651..334f1ce025 100644 --- a/src/test/java/seedu/duke/DukeTest.java +++ b/src/test/java/seedu/binbash/DukeTest.java @@ -1,4 +1,4 @@ -package seedu.duke; +package seedu.binbash; import static org.junit.jupiter.api.Assertions.assertTrue; From 203eee395e808ef4f58634f2ae8de73c7f58dd2d Mon Sep 17 00:00:00 2001 From: YHWong20 Date: Mon, 11 Mar 2024 15:53:35 +0800 Subject: [PATCH 02/14] Add ItemList class --- src/main/java/seedu/binbash/ItemList.java | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/seedu/binbash/ItemList.java diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java new file mode 100644 index 0000000000..30ff109fd5 --- /dev/null +++ b/src/main/java/seedu/binbash/ItemList.java @@ -0,0 +1,28 @@ +package seedu.binbash; + +import java.util.List; +import java.util.ArrayList; + +public class ItemList { + private final List itemList; + + public ItemList() { + itemList = new ArrayList<>(); + } + + public List getItemList() { + return itemList; + } + + /** + * Test method + */ + public void addItem(Item item) { + itemList.add(item); + } + + @Override + public String toString() { + return itemList.toString(); + } +} From 4647893b7e2166dafd2e99bc3eecb710d9282255 Mon Sep 17 00:00:00 2001 From: YHWong20 Date: Mon, 11 Mar 2024 15:53:43 +0800 Subject: [PATCH 03/14] Add Item class --- src/main/java/seedu/binbash/Item.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/seedu/binbash/Item.java diff --git a/src/main/java/seedu/binbash/Item.java b/src/main/java/seedu/binbash/Item.java new file mode 100644 index 0000000000..55c35ab8a6 --- /dev/null +++ b/src/main/java/seedu/binbash/Item.java @@ -0,0 +1,24 @@ +package seedu.binbash; + +public class Item { + private final String itemName; + private final String itemDescription; + + public Item(String itemName, String itemDescription) { + this.itemName = itemName; + this.itemDescription = itemDescription; + } + + public String getItemName() { + return itemName; + } + + public String getItemDescription() { + return itemDescription; + } + + @Override + public String toString() { + return itemName + ": " + itemDescription; + } +} From 0d4df548ad014c86ba78ef8eb31e8eaa57537815 Mon Sep 17 00:00:00 2001 From: YHWong20 Date: Mon, 11 Mar 2024 16:39:16 +0800 Subject: [PATCH 04/14] Update application name in gradle config --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ea82051fab..77a37dc021 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ test { } application { - mainClass.set("seedu.duke.Duke") + mainClass.set("seedu.binbash.Duke") } shadowJar { From 58750f929de79baf60fa83d0e997ab1ef52c11e8 Mon Sep 17 00:00:00 2001 From: PureUsagi Date: Mon, 11 Mar 2024 17:14:58 +0800 Subject: [PATCH 05/14] Add Command abstract class. --- src/main/java/seedu/binbash/command/Command.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/seedu/binbash/command/Command.java 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..b9f14c0e8f --- /dev/null +++ b/src/main/java/seedu/binbash/command/Command.java @@ -0,0 +1,16 @@ +package seedu.binbash.command; + +import java.util.regex.Pattern; +import seedu.binbash.ItemList; + +public abstract class Command { + protected ItemList itemList; + public static final String COMMAND_STRING = "command"; + public static final Pattern COMMAND_FORMAT = + Pattern.compile("(?\\S+)(?.*)"); + protected Command(ItemList itemList) { + this.itemList = itemList; + } + + abstract public String execute(); +} From 0939422c7153df5e1d59158877abed3903f4568e Mon Sep 17 00:00:00 2001 From: PureUsagi Date: Mon, 11 Mar 2024 17:31:43 +0800 Subject: [PATCH 06/14] Add deleteItem method to ItemList class. --- src/main/java/seedu/binbash/ItemList.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index 30ff109fd5..c0e44e9056 100644 --- a/src/main/java/seedu/binbash/ItemList.java +++ b/src/main/java/seedu/binbash/ItemList.java @@ -21,6 +21,15 @@ public void addItem(Item item) { itemList.add(item); } + public String deleteItem(int index) { + Item tempItem = itemList.get(index - 1); + 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(); From 32eababf78e2580de50fdbdfb30771ae91781df9 Mon Sep 17 00:00:00 2001 From: PureUsagi Date: Mon, 11 Mar 2024 17:31:58 +0800 Subject: [PATCH 07/14] Add Delete Command Class. --- .../seedu/binbash/command/DeleteCommand.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/seedu/binbash/command/DeleteCommand.java 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..1d38ee8620 --- /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 final static String COMMAND_WORD = "delete"; + public final static 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); + } +} From eb7789fbaa720ea9f64926a3387828f7082df78d Mon Sep 17 00:00:00 2001 From: PureUsagi Date: Mon, 11 Mar 2024 17:53:17 +0800 Subject: [PATCH 08/14] Reformat code to be compliant with checkstyle. --- src/main/java/seedu/binbash/command/Command.java | 5 +++-- src/main/java/seedu/binbash/command/DeleteCommand.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/binbash/command/Command.java b/src/main/java/seedu/binbash/command/Command.java index b9f14c0e8f..863bd18a14 100644 --- a/src/main/java/seedu/binbash/command/Command.java +++ b/src/main/java/seedu/binbash/command/Command.java @@ -4,13 +4,14 @@ import seedu.binbash.ItemList; public abstract class Command { - protected ItemList itemList; 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; } - abstract public String execute(); + public abstract String execute(); } diff --git a/src/main/java/seedu/binbash/command/DeleteCommand.java b/src/main/java/seedu/binbash/command/DeleteCommand.java index 1d38ee8620..1fcfb1f314 100644 --- a/src/main/java/seedu/binbash/command/DeleteCommand.java +++ b/src/main/java/seedu/binbash/command/DeleteCommand.java @@ -4,8 +4,8 @@ import seedu.binbash.ItemList; public class DeleteCommand extends Command { - public final static String COMMAND_WORD = "delete"; - public final static Pattern COMMAND_FORMAT = + public static final String COMMAND_WORD = "delete"; + public static final Pattern COMMAND_FORMAT = Pattern.compile("delete\\s(?\\d+)"); protected int index; From 15ab9d7e2ff62cb34f21b1d159e3bb131a1cd79a Mon Sep 17 00:00:00 2001 From: PureUsagi Date: Tue, 12 Mar 2024 19:04:06 +0800 Subject: [PATCH 09/14] Changed Constant COMMAND_WORD to COMMAND_STRING. --- src/main/java/seedu/binbash/command/DeleteCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/binbash/command/DeleteCommand.java b/src/main/java/seedu/binbash/command/DeleteCommand.java index 1fcfb1f314..351456c11e 100644 --- a/src/main/java/seedu/binbash/command/DeleteCommand.java +++ b/src/main/java/seedu/binbash/command/DeleteCommand.java @@ -4,7 +4,7 @@ import seedu.binbash.ItemList; public class DeleteCommand extends Command { - public static final String COMMAND_WORD = "delete"; + public static final String COMMAND_STRING = "delete"; public static final Pattern COMMAND_FORMAT = Pattern.compile("delete\\s(?\\d+)"); protected int index; From 292f6bedad0d178ff02b53d45c873b5e5776d9fc Mon Sep 17 00:00:00 2001 From: PureUsagi Date: Tue, 12 Mar 2024 19:07:40 +0800 Subject: [PATCH 10/14] Simplify Delete method in ItemList. --- src/main/java/seedu/binbash/ItemList.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index c0e44e9056..4e1cf42ffc 100644 --- a/src/main/java/seedu/binbash/ItemList.java +++ b/src/main/java/seedu/binbash/ItemList.java @@ -22,8 +22,7 @@ public void addItem(Item item) { } public String deleteItem(int index) { - Item tempItem = itemList.get(index - 1); - itemList.remove(index - 1); + Item tempItem = itemList.remove(index - 1); String output = "Got it! I've removed the following item:" + String.format("\t%s", tempItem); From d6eeee7b77238aaa80b1d02165a2da3179196619 Mon Sep 17 00:00:00 2001 From: nkotaa Date: Wed, 13 Mar 2024 15:09:14 +0800 Subject: [PATCH 11/14] Add Skeleton Ui Class --- src/main/java/seedu/binbash/ui/Ui.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/seedu/binbash/ui/Ui.java diff --git a/src/main/java/seedu/binbash/ui/Ui.java b/src/main/java/seedu/binbash/ui/Ui.java new file mode 100644 index 0000000000..4d7dbd77ba --- /dev/null +++ b/src/main/java/seedu/binbash/ui/Ui.java @@ -0,0 +1,21 @@ +package seedu.binbash.ui; + +import java.util.Scanner; + +public class Ui { + private static final String WELCOME_MESSAGE = "Welcome to BinBash!"; + private static final String GOODBYE_MESSAGE = "Bye!"; + private static final String LINE_DIVIDER = "-------------------------------------------------------------"; + + private Scanner in; + private boolean isUserActive; + + public Ui() { + in = new Scanner(System.in); + isUserActive = true; + } + + public boolean isUserActive() { + return isUserActive; + } +} From 7e6d5e1f8fbbcbc435734313b9836c435add9613 Mon Sep 17 00:00:00 2001 From: nkotaa Date: Wed, 13 Mar 2024 16:04:07 +0800 Subject: [PATCH 12/14] Add Rudimentary Helper Methods --- src/main/java/seedu/binbash/ui/Ui.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/seedu/binbash/ui/Ui.java b/src/main/java/seedu/binbash/ui/Ui.java index 4d7dbd77ba..c1392fdedb 100644 --- a/src/main/java/seedu/binbash/ui/Ui.java +++ b/src/main/java/seedu/binbash/ui/Ui.java @@ -18,4 +18,16 @@ public Ui() { public boolean isUserActive() { return isUserActive; } + + public void greet() { + talk(WELCOME_MESSAGE); + } + + public void farewell() { + talk(GOODBYE_MESSAGE); + } + + public void talk(String line) { + System.out.println(LINE_DIVIDER + "\n" + line + "\n" + LINE_DIVIDER); + } } From 7c0fdcbbb6381be9a19829ab19e3497411f6a6be Mon Sep 17 00:00:00 2001 From: nur-haziq Date: Wed, 13 Mar 2024 21:50:33 +0800 Subject: [PATCH 13/14] Add ListCommand.java Add skeleton code for ListCommand class --- .../seedu/binbash/command/ListCommand.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/seedu/binbash/command/ListCommand.java diff --git a/src/main/java/seedu/binbash/command/ListCommand.java b/src/main/java/seedu/binbash/command/ListCommand.java new file mode 100644 index 0000000000..1eac5c4804 --- /dev/null +++ b/src/main/java/seedu/binbash/command/ListCommand.java @@ -0,0 +1,20 @@ +package seedu.binbash.command; + +import seedu.binbash.ItemList; +import java.util.regex.Pattern; + +public class ListCommand extends Command { + + public static final String COMMAND_STRING = "list"; + public static final Pattern COMMAND_FORMAT = + Pattern.compile("^list"); + + + public ListCommand(ItemList itemList) { + super(itemList); + } + + public String execute() { + return itemList.printList(); + } +} From 24d8f4c68275ac72f84baf8d382becacd6148ac0 Mon Sep 17 00:00:00 2001 From: nur-haziq Date: Wed, 13 Mar 2024 21:54:34 +0800 Subject: [PATCH 14/14] ItemList.java: Add method to print list --- src/main/java/seedu/binbash/ItemList.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/seedu/binbash/ItemList.java b/src/main/java/seedu/binbash/ItemList.java index 4e1cf42ffc..7ecaafda17 100644 --- a/src/main/java/seedu/binbash/ItemList.java +++ b/src/main/java/seedu/binbash/ItemList.java @@ -29,6 +29,26 @@ public String deleteItem(int index) { return output; } + /** + * DO LET ME KNOW IF THE METHOD NAME IS WEIRD. IM RETURNING A STRING REPRESENTATION INSTEAD + * OF CALLING SOUT TO STAY CONSISTENT WITH THE OTHER COMMANDS BEHAVIOUR. SO IT DOESN'T ACTUALLY + * PRINT THE LIST. IF THERES A BETTER NAME LMK THANKS + * + * Returns a string representation of all the items in the list. Each item's string + * representation is obtained by calling its `toString` method. + * + * @return A concatenated string of all item representations in the list, each on a new line. + */ + public String printList() { + String output = ""; + + for (Item item: itemList) { + output += item.toString() + System.lineSeparator(); + } + + return output; + } + @Override public String toString() { return itemList.toString();