From 7c0fdcbbb6381be9a19829ab19e3497411f6a6be Mon Sep 17 00:00:00 2001 From: nur-haziq Date: Wed, 13 Mar 2024 21:50:33 +0800 Subject: [PATCH 1/2] 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 2/2] 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();