Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Shu committed Apr 15, 2024
2 parents 9fc25e7 + 75adf1f commit 1da147b
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 247 deletions.
Empty file removed StockMasterData.txt
Empty file.
Binary file modified docs/Diagrams/Images/Cashier/CashierSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/Diagrams/Images/Storage/Storage_sequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Command -> Cashier: addItem(transaction)
activate Cashier
Cashier -> Cashier: transactions.add(transaction)
return
Command --> TextUi: showSellMessage()
Command -> TextUi: showSellMessage()
activate TextUi
return
alt if itemName is not given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ participant ":TotalProfitCommand" as TotalProfitCommand
participant ":Cashier" as Cashier
participant ":TextUi" as TextUi


mainframe sd
alt get total revenue
TotalProfitCommand -> Cashier: getTotalRevenue()
activate Cashier
Expand All @@ -21,5 +23,4 @@ else get total profit
TotalProfitCommand -> TextUi: replyToUser("You have earned {totalProfit} in profits so far.")
end


@enduml
61 changes: 32 additions & 29 deletions docs/Diagrams/PUML files/Storage/Storage_sequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
@startuml
!include ../Style.puml
participant Client
participant Storage
participant Itemlist
participant Item
participant Scanner
participant File
participant ":Client"
participant ":Storage"
participant ":Itemlist"
participant ":Item"
participant ":Scanner"
participant ":File"

Client -> Storage: readFromFile(fileName)
activate Storage
Storage -> File: new File(fileName)
activate File
Storage -> Scanner: new Scanner(File)
activate Scanner
Scanner --> File: interpretLines(scanner)
File --> Storage: Close Scanner
deactivate Scanner
deactivate File
deactivate Storage
":Client" -> ":Storage": readFromFile(fileName)
activate ":Storage"
":Storage" -> ":File": new File(fileName)
activate ":File"
":Storage" -> ":Scanner": new Scanner(File)
activate ":Scanner"
":Scanner" -> ":File": interpretLines(scanner)
":File" --> ":Storage": Close Scanner
deactivate ":Scanner"
deactivate ":File"
":Storage" --> ":Client"
deactivate ":Storage"

Client -> Storage: addToFile(items)
activate Storage
Storage -> Itemlist: addItem(toAdd)
activate Itemlist
Itemlist --> Storage
deactivate Itemlist
Storage -> Storage: updateFile(descriptionAdded, true)
deactivate Storage
":Client" -> ":Storage": addToFile(items)
activate ":Storage"
":Storage" -> ":Itemlist": addItem(toAdd)
activate ":Itemlist"
":Itemlist" --> ":Storage"
deactivate ":Itemlist"
":Storage" -> ":Storage": updateFile(descriptionAdded, true)
":Storage" --> ":Client"
deactivate ":Storage"

Client -> Storage: overwriteFile(items)
activate Storage
":Client" -> ":Storage": overwriteFile(items)
activate ":Storage"
loop for each item in items
Storage -> Storage: updateFile(descriptionAdded, ifAppend)
":Storage" -> ":Storage": updateFile(descriptionAdded, ifAppend)
end
deactivate Storage
":Storage" --> ":Client"
deactivate ":Storage"
@enduml
2 changes: 1 addition & 1 deletion docs/team/fureimi.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ only want to see their marked items. The mark feature is explained below.
- **Documentation**:
- User Guide:
- Added documentation for the features `list_items`, `mark`, `unmark` and `edit`
- Update the command summary
- Update the command summary.
- Developer Guide:
- Added class diagram of the `EditCommand` class.
- Added implementation details and sequence diagram of both the `list_items` and `edit` features.
2 changes: 1 addition & 1 deletion docs/team/lowtl.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ manage and operate their business.
**Code Contributed:**
[Reposense Link](https://nus-cs2113-ay2324s2.github.io/tp-dashboard/?search=LowTL&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2024-02-23&tabOpen=true&tabType=authorship&tabAuthor=LowTL&tabRepo=AY2324S2-CS2113-T15-4%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=functional-code&authorshipIsBinaryFileTypeChecked=false&authorshipIsIgnoredFilesChecked=false)

### Features implemented
### Enhancements implemented
* `Cashier` class.
* Allows users to create and store `Transactions`, in an extension of the `item` class.
* Contains the `getTotalProfit`, `getTotalRevenue`, and `getBestseller` methods, for basic business analysis.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/command/BestsellerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void execute() throws EmptyListException {
String bs = Cashier.getBestseller();
try {
if (bs == null) {
throw new EmptyListException("Transaction");
throw new EmptyListException("Bestseller");
}
} catch (EmptyListException e) {
LOGGER.warning("No transaction found.");
Expand Down
52 changes: 39 additions & 13 deletions src/main/java/command/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,25 @@ public class ListCommand extends Command{
protected boolean isListMarked = false;

/**
* Instantiates a <code>ListCommand</code> with the <code>ArrayList arrayList</code>
* and any other modifiers available to that type of <code>ArrayList</code>.
*/
* Instantiates a <code>ListCommand</code> with the <code>ArrayList arrayList</code>
* and any other modifiers available to that type of <code>ArrayList</code>.
*/
public ListCommand(ArrayList<Item> arrayList, String category, boolean isListMarked) {
this.itemList= arrayList;
this.category = category;
this.isListMarked = isListMarked;
LOGGER.info("List items command generated.");
try {
if (arrayList == null || arrayList.isEmpty()) {
if (category.equals("NA") && !isListMarked) {
throw new EmptyListException("Item");
} else {
throw new EmptyListException("Filter Item");
}
}
} catch (EmptyListException e) {
LOGGER.warning("Empty item list.");
}
}

/**
Expand All @@ -43,13 +55,31 @@ public ListCommand(ArrayList<Transaction> arrayList, String itemName) {
} else {
this.transactionList = Cashier.getTransactions(itemName);
}
try {
if (transactionList == null || transactionList.isEmpty()) {
if (itemName.equals("NA")) {
throw new EmptyListException("Transaction");
} else {
throw new EmptyListException("Filter Transaction");
}
}
} catch (EmptyListException e) {
LOGGER.warning("Empty list detected.");
}
}

/**
* Instantiates a <code>ListCommand</code> with the <code>ArrayList arrayList</code>
* and any other modifiers available to that type of <code>ArrayList</code>.
*/
public ListCommand(ArrayList<Promotion> arrayList) {
try {
if (arrayList.isEmpty()) {
throw new EmptyListException("Promotion");
}
} catch (EmptyListException e) {
LOGGER.warning("Empty list detected.");
}
this.promotionList = arrayList;
}

Expand All @@ -60,26 +90,22 @@ public String getCategory() {
/**
* Runs the list command with 3 cases
* Depending on which ArrayList is not empty, it prints that list.
* @throws EmptyListException if all Lists are empty.
* */
//@@author Fureimi
public void execute() throws EmptyListException {
public void execute() {

if (containsTransactions(transactionList)) {
showTransactionList();
LOGGER.info("Transactions listed.");
} else if (containsPromotions(promotionList)) {
showPromotionList();
LOGGER.info("Promotions listed.");
} else if (category.equals("NA") && !isListMarked) {
TextUi.showList(itemList);
LOGGER.info("All items listed.");
} else if (containsItems(itemList)) {
} else if (containsItems(itemList) && (!category.equals("NA") || isListMarked)) {
showCustomizedItemList();
LOGGER.info("Items listed.");
} else {
LOGGER.warning("No results found.");
throw new EmptyListException("Empty List");
LOGGER.info("Customised item listed.");
} else if (containsItems(itemList) && category.equals("NA") && !isListMarked) {
TextUi.showList(itemList);
LOGGER.info("All item listed.");
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/command/TotalProfitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public TotalProfitCommand(CommandType command) {
public void execute() {
float totalProfit = command.equals(CommandType.TOTAL_PROFIT) ?
Cashier.getTotalProfit() : Cashier.getTotalRevenue();
if (totalProfit == 0) {
return;
}
TextUi.replyToUser("You have earned " + totalProfit +
" in "+ (command.equals(CommandType.TOTAL_PROFIT) ? "profits" : "revenue") + " so far.");
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/common/HelpMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class HelpMessages {
"|------------|------------------------------------------------------------------------------|\n" +
"| list items | list_items [marked] [cat/CATEGORY] |\n" +
"|------------|------------------------------------------------------------------------------|\n" +
"| list | list_transactions [item/ITEM_NAME] |\n" +
"| transaction| |\n" +
"|------------|------------------------------------------------------------------------------|\n" +
"| add | add ITEM_NAME qty/QUANTITY_OF_ITEM /UNIT_OF_MEASUREMENT [cat/CATEGORY] |\n" +
"| | buy/BUY_PRICE sell/SELL_PRICE |\n" +
"|------------|------------------------------------------------------------------------------|\n" +
Expand Down Expand Up @@ -233,7 +236,7 @@ public class HelpMessages {
"|-------------------|-----------------------------------------------------------------------|\n" +
"| list_transactions | list_transaction [item/ITEM_NAME] |\n" +
"|-------------------|-----------------------------------------------------------------------|\n" +
"| example: | list_transaction item/apple |\n" +
"| example: | list_transactions item/apple |\n" +
"|___________________|_______________________________________________________________________|\n";

public static final String INVALID_HELP_COMMAND = "Please input a valid command to inquire about.";
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public class Messages {

public static final String UNABLE_TO_DELETE = "There is a promotion that exists for this item. Please remove the " +
"promotion before deleting the item.";
public static final String EMPTY_ITEM_LIST = "There are no items with your search query.";
public static final String EMPTY_TRANSACTION_LIST = "There are no transactions with your search query.";
public static final String EMPTY_ITEM_LIST = "There are no items at the moment.";
public static final String EMPTY_TRANSACTION_LIST = "There are no transactions at the moment.";
public static final String EMPTY_FILTERED_ITEM_LIST = "There are no items with your search query.";
public static final String EMPTY_FILTERED_TRANSACTION_LIST = "There are no transactions with your search query.";
public static final String EMPTY_LIST = "There is nothing here! Time to spend some money and stock em up!";
public static final String WELCOME_MESSAGE = "Welcome to StockMaster, where you can master the knowledge on your " +
"Stock!";
Expand Down Expand Up @@ -96,5 +98,8 @@ public class Messages {

public static final String INVALID_VALUE = "Please input a valid amount.";

public static final String NO_BESTSELLER = "There are no transactions. Please add a transaction " +
"before retrying the command.";

public static final String EMPTY_PROMOTION_LIST = "There are no promotions at the moment.";
}
12 changes: 12 additions & 0 deletions src/main/java/exceptions/EmptyListException.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@
public class EmptyListException extends Exception {
public EmptyListException(String error) {
switch (error) {
case "Filter Item":
System.out.println(Messages.EMPTY_FILTERED_ITEM_LIST);
break;
case "Item":
System.out.println(Messages.EMPTY_ITEM_LIST);
break;
case "Filter Transaction":
System.out.println(Messages.EMPTY_FILTERED_TRANSACTION_LIST);
break;
case "Transaction":
System.out.println(Messages.EMPTY_TRANSACTION_LIST);
break;
case "Promotion":
System.out.println(Messages.EMPTY_PROMOTION_LIST);
break;
case "Empty List":
System.out.println("No results found.");
break;
case "Bestseller":
System.out.println(Messages.NO_BESTSELLER);
break;
default:
System.out.println(error);
}
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/itemlist/Cashier.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ public static ArrayList<Transaction> getTransactions(String itemName) {
results.add(t);
}
}
LOGGER.info("Transactions filtered.");
return results;
} else {
LOGGER.warning("No transactions found.");
return null;
}
return results;
}

public static float getTotalRevenue() {
float totalRevenue = 0;
try {
ArrayList<Transaction> allTransactions = getTransactions();
if (allTransactions.isEmpty()) {
throw new EmptyListException("Transaction");
throw new EmptyListException("Bestseller");
}
for (Transaction t : allTransactions) {
totalRevenue += t.getTotalPrice();
Expand All @@ -60,7 +56,7 @@ public static float getTotalProfit() {
float totalProfit = 0;
try {
if (transactions.isEmpty()) {
throw new EmptyListException("Transaction");
throw new EmptyListException("Bestseller");
}
for (Transaction t : transactions) {
totalProfit += t.getProfit();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/StockMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static void initLogger() {
}
}

private void normalOperation() throws IOException, CommandFormatException,
private void normalOperation() throws CommandFormatException,
InvalidDateException, EmptyListException {
String userInput;
do {
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,20 @@ public static void replyToUser(String... message) {
* @param arrayList The arraylist to show to the user.
*/
public static <T> void showList(ArrayList<T> arrayList) {
if (arrayList.isEmpty()) {
if (arrayList == null || arrayList.isEmpty()) {
replyToUser(Messages.EMPTY_LIST);
return;
}
replyToUser("List: ");
int index = 1;
for (T item : arrayList) {
if (item == null) {
break;
} else {
replyToUser("List: ");
int index = 1;
for (T item : arrayList) {
if (item == null) {
break;
}
String listItem = index + ". " + item;
replyToUser(listItem);
index++;
}
String listItem = index + ". " + item;
replyToUser(listItem);
index++;
}
}

Expand Down Expand Up @@ -136,10 +137,8 @@ public static void showSellMessage(String item, int sellQuantity, int remainingQ
* @param isListMarked Whether the items listed are marked items.
*/
public static void showCustomizedList(ArrayList<Item> arrayList, String category, boolean isListMarked) {
if (arrayList.isEmpty()) {
replyToUser(Messages.EMPTY_LIST);
// case 1: user wants to list all items of a certain category
} else if (!category.equals("NA") && !isListMarked) {
// case 1: user wants to list all items of a certain category
if (!category.equals("NA") && !isListMarked) {
int flag = 0;
int counter = 1;
for (Item item : arrayList) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/command/BestsellerCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testExecuteWithEmptyBestseller() throws EmptyListException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStream));
bestsellerCommand.execute();
String expected = Messages.EMPTY_TRANSACTION_LIST + System.lineSeparator();
String expected = Messages.NO_BESTSELLER + System.lineSeparator();
assertEquals(expected, outputStream.toString());
} catch (EmptyListException e) {
throw new RuntimeException(e);
Expand Down
Loading

0 comments on commit 1da147b

Please sign in to comment.