forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'AY2324S2-CS2113T-T09-2:master' into master
- Loading branch information
Showing
9 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/seedu/duke/Duke.java → src/main/java/seedu/binbash/Duke.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package seedu.duke; | ||
package seedu.binbash; | ||
|
||
import java.util.Scanner; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/test/java/seedu/duke/DukeTest.java → src/test/java/seedu/binbash/DukeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|