Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to add items into ItemList #34

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/seedu/binbash/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ public List<Item> 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) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/seedu/binbash/command/AddCommand.java
Original file line number Diff line number Diff line change
@@ -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(?<itemName>\\s+)\\s/d(?<itemDescription>\\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);
}
}
Loading