Skip to content

Commit

Permalink
Merge branch 'AY2324S2-CS2113T-T09-2:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierLiau34 authored Mar 13, 2024
2 parents 9c5cff0 + f1621c4 commit ce3a5c3
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test {
}

application {
mainClass.set("seedu.duke.Duke")
mainClass.set("seedu.binbash.Duke")
}

shadowJar {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.duke;
package seedu.binbash;

import java.util.Scanner;

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/seedu/binbash/Item.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
56 changes: 56 additions & 0 deletions src/main/java/seedu/binbash/ItemList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package seedu.binbash;

import java.util.List;
import java.util.ArrayList;

public class ItemList {
private final List<Item> itemList;

public ItemList() {
itemList = new ArrayList<>();
}

public List<Item> getItemList() {
return itemList;
}

/**
* Test method
*/
public void addItem(Item item) {
itemList.add(item);
}

public String deleteItem(int index) {
Item tempItem = itemList.remove(index - 1);

String output = "Got it! I've removed the following item:"
+ String.format("\t%s", tempItem);
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();
}
}
17 changes: 17 additions & 0 deletions src/main/java/seedu/binbash/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seedu.binbash.command;

import java.util.regex.Pattern;
import seedu.binbash.ItemList;

public abstract class Command {
public static final String COMMAND_STRING = "command";
public static final Pattern COMMAND_FORMAT =
Pattern.compile("(?<command>\\S+)(?<arguments>.*)");
protected ItemList itemList;

protected Command(ItemList itemList) {
this.itemList = itemList;
}

public abstract String execute();
}
21 changes: 21 additions & 0 deletions src/main/java/seedu/binbash/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package seedu.binbash.command;

import java.util.regex.Pattern;
import seedu.binbash.ItemList;

public class DeleteCommand extends Command {
public static final String COMMAND_STRING = "delete";
public static final Pattern COMMAND_FORMAT =
Pattern.compile("delete\\s(?<index>\\d+)");
protected int index;

public DeleteCommand(ItemList itemList, int index) {
super(itemList);

this.index = index;
}

public String execute() {
return itemList.deleteItem(index);
}
}
20 changes: 20 additions & 0 deletions src/main/java/seedu/binbash/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
33 changes: 33 additions & 0 deletions src/main/java/seedu/binbash/ui/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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;
}

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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.duke;
package seedu.binbash;

import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down

0 comments on commit ce3a5c3

Please sign in to comment.