From 7eb88d5347dea7366f328d5077d50d11f15b62ee Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 09:33:16 +0800 Subject: [PATCH 01/18] Enhance error handling in Parser class for list_ingredients command and list_sale command. Fixes #320 --- src/main/java/seedu/cafectrl/parser/Parser.java | 17 ++++++++++++----- .../java/seedu/cafectrl/ui/ErrorMessages.java | 12 +++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index 9a0447681d..d270b61a46 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -68,7 +68,7 @@ public class Parser implements ParserUtil { + "qty/([A-Za-z0-9\\s]+)"; /** The rest of Command Handler Patterns*/ - private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(.+)"; + private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "index/(.+)"; private static final String DELETE_ARGUMENT_STRING = "(\\d+)"; private static final String EDIT_PRICE_ARGUMENT_STRING = "dish/(.*)\\sprice/(.*)"; private static final String BUY_INGREDIENT_ARGUMENT_STRING = "(ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+" @@ -445,14 +445,18 @@ private static Command prepareListIngredient(Menu menu, String arguments, Ui ui) } try { - int dishIndex = Integer.parseInt(matcher.group(1)); + int dishIndex = Integer.parseInt(matcher.group(1).trim()); + + if (dishIndex < 0) { + throw new Exception(); + } if (!menu.isValidDishIndex(dishIndex)) { return new IncorrectCommand(ErrorMessages.UNLISTED_DISH, ui); } return new ListIngredientCommand(dishIndex, menu, ui); - } catch (NumberFormatException e) { + } catch (Exception e) { return new IncorrectCommand(ErrorMessages.INVALID_DISH_INDEX_TO_LIST, ui); } } @@ -642,9 +646,12 @@ private static Command prepareShowSalesByDay(String arguments, Ui ui, Sales sale } try { - int day = Integer.parseInt(matcher.group(1)); + int day = Integer.parseInt(matcher.group(1).trim()); + if (day < 0) { + throw new Exception(); + } return new ListSaleByDayCommand(day, ui, sales, menu); - } catch (NumberFormatException e) { + } catch (Exception e) { return new IncorrectCommand(ErrorMessages.INVALID_DAY_FORMAT, ui); } } diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index 9d6a5dd672..9c81151eb4 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -54,13 +54,14 @@ public class ErrorMessages { + "No worries, new order list has been created"; public static final String INVALID_SHOW_SALE_DAY_FORMAT_MESSAGE = "Error: " + "Incorrect format for the show_sale command.\n"; - public static final String INVALID_DAY_FORMAT = "Sorry, please enter a valid integer " + public static final String INVALID_DAY_FORMAT = "Sorry, please enter a valid integer(>0)" + "for the 'day' field!"; public static final String EDIT_SAME_PRICE = "New price is exactly the same as old price, " + "is that what you want?"; - public static final String INVALID_DISH_INDEX_TO_LIST = "Please enter a valid integer for the dish index. \n"; + public static final String INVALID_DISH_INDEX_TO_LIST = "Please enter a valid integer(>0) " + + "for the 'index' field."; public static final String UNLISTED_DISH = "Oh no, this dish does not exist! \n" - + " please run the command list_menu to view the existing dishes."; + + "Please run the command list_menu to view the existing dishes."; public static final String INVALID_SALE_DAY = "Oh no, we have not reached the day entered!"; public static final String EMPTY_UNIT_MESSAGE = "Unit cannot be empty! Please use either g or ml :)"; public static final String INVALID_UNIT_MESSAGE = "Invalid unit! Please use either g or ml :)"; @@ -76,6 +77,11 @@ public class ErrorMessages { + "did you forget to include it in your command?"; public static final String INVALID_MENU_DATA = "menu.txt: Invalid format, this dish will be removed -> "; + public static final String INVALID_SALES_DATA = "orders.txt: Invalid format, this order will be removed -> "; + public static final String INVALID_ORDER_DATA = "orders.txt: Invalid dish, this order will be removed -> "; + public static final String INACCURATE_ORDER_COST_DATA = "orders.txt: The total order cost of this order -> \"%s\" " + + "is inaccurate and will hence be updated from %.2f to %.2f instead."; + public static final String NAME_CANNOT_CONTAIN_SPECIAL_CHAR = "Is there a special character" + "in the name?\n I have poor memory and am unable to remember names with special characters" + ",\nso could you remove them?"; From 63b9403d56dfafda1135144bacabc4d116e493a1 Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 09:33:54 +0800 Subject: [PATCH 02/18] Ignore case while searching for ingredients in pantry. --- src/main/java/seedu/cafectrl/data/Pantry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java index 5afecb83bb..25de5b4b55 100644 --- a/src/main/java/seedu/cafectrl/data/Pantry.java +++ b/src/main/java/seedu/cafectrl/data/Pantry.java @@ -133,7 +133,7 @@ public boolean isDishCooked(ArrayList dishIngredients) { */ private Ingredient getIngredient(Ingredient dishIngredient) { return pantryStock.stream() - .filter(ingredient -> ingredient.getName().trim().equals(dishIngredient.getName().trim())) + .filter(ingredient -> ingredient.getName().trim().equalsIgnoreCase(dishIngredient.getName().trim())) .findFirst() .orElse(null); } From fd5b2ffa9b4e526f0d9e5aafde53441b627e014d Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 09:41:49 +0800 Subject: [PATCH 03/18] Refactor decoding of sales to make it more modular and add in a check to see if the decoded total order cost matches the calculated order cost. Fixes #320 --- src/main/java/seedu/cafectrl/data/Sales.java | 2 +- .../java/seedu/cafectrl/storage/Decoder.java | 135 +++++++++++++----- 2 files changed, 104 insertions(+), 33 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/Sales.java b/src/main/java/seedu/cafectrl/data/Sales.java index 9548a0fa3e..75b8cb5c22 100644 --- a/src/main/java/seedu/cafectrl/data/Sales.java +++ b/src/main/java/seedu/cafectrl/data/Sales.java @@ -13,7 +13,7 @@ */ public class Sales { private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); - private static final int DAY_DISPLAY_OFFSET = 1; + public static final int DAY_DISPLAY_OFFSET = 1; private static ArrayList orderLists; private int daysAccounted; diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 492fd6a06e..a9a437e6f4 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -11,7 +11,6 @@ import seedu.cafectrl.data.dish.Ingredient; import seedu.cafectrl.parser.Parser; import seedu.cafectrl.ui.ErrorMessages; -import seedu.cafectrl.ui.Messages; import seedu.cafectrl.ui.Ui; import java.util.ArrayList; @@ -31,6 +30,7 @@ public class Decoder { private static final String INGREDIENT_DIVIDER = " - "; private static final Ui ui = new Ui(); private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + //@@author ShaniceTang /** * Decodes an ArrayList of string lines into a Menu object, reconstructing its content. @@ -87,6 +87,7 @@ private static void checkUnitValidity(String unit) throws Exception { throw new Exception(); } } + //@@author //@@author ziyi105 /** @@ -166,45 +167,116 @@ public static Sales decodeSales(ArrayList textLines, Menu menu) { logger.info("Decoding orders.txt to Sales..."); boolean salesOrderTextTamperDetectionMessagePrinted = false; ArrayList orderLists = new ArrayList<>(); + if(textLines.isEmpty()) { return new Sales(); } + //for each 'order' in text file for (String line : textLines) { logger.info("Line to decode: " + line); - try { - String[] orderData = line.split(DIVIDER); - int day = Integer.parseInt(orderData[0].trim()) - 1; - String dishName = orderData[1].trim(); - if (dishName.equals(Encoder.NULL_ORDER_DAY)) { - orderLists = fillOrderListSize(orderLists, day); - continue; - } - int quantity = Integer.parseInt(orderData[2].trim()); - float totalOrderCost = Float.parseFloat(orderData[3].trim()); - boolean isComplete = "true".equals(orderData[4].trim()); - Dish dish = menu.getDishFromName(dishName); - if (dish == null) { - ui.showDecodedInvalidDish(dishName); - continue; - } - Order orderedDish = new Order(menu.getDishFromName(dishName), quantity, totalOrderCost, isComplete); - //increase size of orderLists if needed - //this can be used in the event that the text file's first order is not day 0 - orderLists = fillOrderListSize(orderLists, day); - orderLists.get(day).addOrder(orderedDish); - } catch (IndexOutOfBoundsException e) { - ui.showToUser(Messages.SALES_LAST_DAY_TEXT_TAMPERED, System.lineSeparator()); - } catch (NumberFormatException e) { - if (!salesOrderTextTamperDetectionMessagePrinted) { - ui.showToUser(Messages.SALES_ORDER_TEXT_TAMPERED, System.lineSeparator()); - salesOrderTextTamperDetectionMessagePrinted = true; - } - } + decodeSalesData(line, orderLists, menu); } return new Sales(orderLists); } + /** + * Decodes the sales data from a single order line and adds it to the list of OrderList objects. + * + * @param orderLine The order line in the format "day|dishName|quantity|totalOrderCost|isComplete". + * @param orderLists The list of OrderList objects to which the decoded order will be added. + * @param menu Menu instance to retrieve Dish objects based on dishName. + */ + private static void decodeSalesData(String orderLine, ArrayList orderLists, Menu menu) { + try { + String[] orderData = orderLine.split(DIVIDER); + int day = Integer.parseInt(orderData[0].trim()) - Sales.DAY_DISPLAY_OFFSET; + String dishName = orderData[1].trim(); + + //@@author Cazh1 + //keeps track of the number of days cafe has been operating for + if (dishName.equals(Encoder.NULL_ORDER_DAY)) { + fillOrderListSize(orderLists, day); + return; + } + //@@author + + int quantity = Integer.parseInt(orderData[2].trim()); + float decodedTotalOrderCost = Float.parseFloat(orderData[3].trim()); + boolean isComplete = "true".equals(orderData[4].trim()); + + boolean isDataAccurate = isOrderDataAccurate(orderLine, menu, dishName, quantity, decodedTotalOrderCost); + if (!isDataAccurate) { + return; + } + + //creates new order and adds to orderList for specific day + Order orderedDish = new Order(menu.getDishFromName(dishName), quantity, decodedTotalOrderCost, isComplete); + fillOrderListSize(orderLists, day); + orderLists.get(day).addOrder(orderedDish); + } catch (Exception e) { + logger.log(Level.WARNING, "Line corrupted: " + e.getMessage(), e); + ui.showToUser(ErrorMessages.INVALID_SALES_DATA + orderLine); + } + } + + /** + * Checks if the order data is accurate by checking if dish exists and + * if the decoded total order cost corresponds to the calculated order cost + * + * @param orderLine The order line in the format "day|dishName|quantity|totalOrderCost|isComplete". + * @param menu Menu instance to retrieve Dish objects based on dishName. + * @param dishName The name of the dish in the order. + * @param quantity The quantity of the dish in the order. + * @param decodedTotalOrderCost The decoded total order cost from the order line. + * @return True if the order data is accurate, false otherwise. + */ + private static boolean isOrderDataAccurate(String orderLine, Menu menu, String dishName, + int quantity, float decodedTotalOrderCost) { + Dish dish = menu.getDishFromName(dishName); + boolean isAccurateData = isDishValid(orderLine, dish) && + isOrderCostAccurate(orderLine, dish, quantity, decodedTotalOrderCost); + return isAccurateData; + } + + /** + * Checks if the Dish is valid (exists in menu) and shows an error message if it's not. + * + * @param orderLine The order line in the format "day|dishName|quantity|totalOrderCost|isComplete". + * @param dish The Dish object to be validated. + * @return True if the Dish is valid, false otherwise. + */ + private static boolean isDishValid(String orderLine, Dish dish) { + if (dish == null) { + ui.showToUser(ErrorMessages.INVALID_ORDER_DATA + orderLine); + return false; + } + return true; + } + + /** + * Checks if the decoded total order cost matches the expected total order cost and shows an error message if not. + * + * @param orderLine The order line in the format "day|dishName|quantity|totalOrderCost|isComplete". + * @param dish The Dish object in the order. + * @param quantity The quantity of the dish in the order. + * @param decodedTotalOrderCost The decoded total order cost from the order line. + * @return True if the decoded total order cost matches the expected total order cost, false otherwise. + */ + private static boolean isOrderCostAccurate(String orderLine, Dish dish, + int quantity, float decodedTotalOrderCost) { + float costOfDish = dish.getPrice(); + float expectedTotalOrderCost = quantity * costOfDish; + if (decodedTotalOrderCost != expectedTotalOrderCost) { + String messageToUser = String.format(ErrorMessages.INACCURATE_ORDER_COST_DATA, + orderLine, decodedTotalOrderCost, expectedTotalOrderCost ); + ui.showToUser(messageToUser); + return false; + } + return true; + } + + //@@author Cazh1 /** * Increases the size of the orderlist when there is gap between the previous order and the next @@ -213,11 +285,10 @@ public static Sales decodeSales(ArrayList textLines, Menu menu) { * @param day The day of the next order * @return orderLists after filling in the gaps */ - private static ArrayList fillOrderListSize(ArrayList orderLists, int day) { + private static void fillOrderListSize(ArrayList orderLists, int day) { while (orderLists.size() <= day) { orderLists.add(new OrderList()); } - return orderLists; } } From 350d9ab212b4d73f4ee3fcb83a4a1d62ed0cfcfd Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 09:54:57 +0800 Subject: [PATCH 04/18] Improve coding standard. --- src/main/java/seedu/cafectrl/data/Sales.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/cafectrl/data/Sales.java b/src/main/java/seedu/cafectrl/data/Sales.java index 75b8cb5c22..c27acdcb1f 100644 --- a/src/main/java/seedu/cafectrl/data/Sales.java +++ b/src/main/java/seedu/cafectrl/data/Sales.java @@ -12,8 +12,8 @@ * The Sales class represents sales data over a period of time, maintaining a collection of order lists. */ public class Sales { - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public static final int DAY_DISPLAY_OFFSET = 1; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private static ArrayList orderLists; private int daysAccounted; From bd50128c80305a6bff565080e67454d418fa810b Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 09:58:23 +0800 Subject: [PATCH 05/18] Edit junit test for list_ingredients command in parser. --- src/test/java/seedu/cafectrl/parser/ParserTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java index f286715e2d..98c5cfe44e 100644 --- a/src/test/java/seedu/cafectrl/parser/ParserTest.java +++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java @@ -48,7 +48,7 @@ public void parseCommand_validListIngredientsCommand_successfulCommandParse() { Sales sales = new Sales(); CurrentDate currentDate = new CurrentDate(); - String userInput = "list_ingredients 1"; + String userInput = "list_ingredients index/1"; ParserUtil parserUtil = new Parser(); Command result = parserUtil.parseCommand(menu, userInput, ui, pantry, sales, currentDate); @@ -85,7 +85,7 @@ public void parseCommand_invalidListIngredientsIndex_returnsErrorMessage() { Pantry pantry = new Pantry(ui); Sales sales = new Sales(); CurrentDate currentDate = new CurrentDate(); - String userInput = "list_ingredients a"; + String userInput = "list_ingredients index/a"; ParserUtil parserUtil = new Parser(); Command result = parserUtil.parseCommand(menu, userInput, ui, pantry, sales, currentDate); @@ -103,7 +103,7 @@ public void parseCommand_listIngredientIndexOutOfBounds_returnsErrorMessage() { Pantry pantry = new Pantry(ui); Sales sales = new Sales(); CurrentDate currentDate = new CurrentDate(); - String userInput = "list_ingredients 1"; + String userInput = "list_ingredients index/1"; ParserUtil parserUtil = new Parser(); Command result = parserUtil.parseCommand(menu, userInput, ui, pantry, sales, currentDate); From 600655231b964badf1504fd50770f52f68023ffe Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 10:04:03 +0800 Subject: [PATCH 06/18] Edit MESSAGE_USAGE for list_ingredients command. --- .../java/seedu/cafectrl/command/ListIngredientCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java index 7413efed9e..a21ab3d230 100644 --- a/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java +++ b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java @@ -16,8 +16,8 @@ public class ListIngredientCommand extends Command { public static final String COMMAND_WORD = "list_ingredients"; public static final String MESSAGE_USAGE = "To list out the ingredients needed " + "along with the quantity for a specific dish:\n" - + "Parameters: DISH_INDEX\n" - + "Example: " + COMMAND_WORD + " 1"; + + "Parameters: index/DISH_INDEX\n" + + "Example: " + COMMAND_WORD + " index/1"; private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Ui ui; From 09d8cc1b37ecf83f5a2690bab3964fa56add0406 Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 10:17:27 +0800 Subject: [PATCH 07/18] Improve code quality by refactoring the decoding of sales. --- .../java/seedu/cafectrl/storage/Decoder.java | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 91c387e829..85103b6268 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -208,7 +208,10 @@ private static void decodeSalesData(String orderLine, ArrayList order float decodedTotalOrderCost = Float.parseFloat(orderData[3].trim()); boolean isComplete = "true".equals(orderData[4].trim()); - boolean isDataAccurate = isOrderDataAccurate(orderLine, menu, dishName, quantity, decodedTotalOrderCost); + Dish dish = menu.getDishFromName(dishName); + + boolean isDataAccurate = isDishValid(orderLine, dish) && + isOrderCostAccurate(orderLine, dish, quantity, decodedTotalOrderCost); if (!isDataAccurate) { return; } @@ -223,25 +226,6 @@ private static void decodeSalesData(String orderLine, ArrayList order } } - /** - * Checks if the order data is accurate by checking if dish exists and - * if the decoded total order cost corresponds to the calculated order cost - * - * @param orderLine The order line in the format "day|dishName|quantity|totalOrderCost|isComplete". - * @param menu Menu instance to retrieve Dish objects based on dishName. - * @param dishName The name of the dish in the order. - * @param quantity The quantity of the dish in the order. - * @param decodedTotalOrderCost The decoded total order cost from the order line. - * @return True if the order data is accurate, false otherwise. - */ - private static boolean isOrderDataAccurate(String orderLine, Menu menu, String dishName, - int quantity, float decodedTotalOrderCost) { - Dish dish = menu.getDishFromName(dishName); - boolean isAccurateData = isDishValid(orderLine, dish) && - isOrderCostAccurate(orderLine, dish, quantity, decodedTotalOrderCost); - return isAccurateData; - } - /** * Checks if the Dish is valid (exists in menu) and shows an error message if it's not. * From 0fe6ef496adf5773118838009d39c79e86aea3c7 Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 10:44:33 +0800 Subject: [PATCH 08/18] Enhance error handling for decoding sales.txt by checking if order status is valid. --- .../java/seedu/cafectrl/storage/Decoder.java | 39 ++++++++++++------- .../java/seedu/cafectrl/ui/ErrorMessages.java | 1 + 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 85103b6268..370fed6eec 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -206,17 +206,18 @@ private static void decodeSalesData(String orderLine, ArrayList order int quantity = Integer.parseInt(orderData[2].trim()); float decodedTotalOrderCost = Float.parseFloat(orderData[3].trim()); - boolean isComplete = "true".equals(orderData[4].trim()); - + String completeStatus = orderData[4].trim(); Dish dish = menu.getDishFromName(dishName); - boolean isDataAccurate = isDishValid(orderLine, dish) && - isOrderCostAccurate(orderLine, dish, quantity, decodedTotalOrderCost); + boolean isDataAccurate = isDishValid(orderLine, dish) + && isOrderCostAccurate(orderLine, dish, quantity, decodedTotalOrderCost) + && isCompleteStatusAccurate(orderLine, completeStatus); if (!isDataAccurate) { return; } //creates new order and adds to orderList for specific day + boolean isComplete = Boolean.parseBoolean(completeStatus.toLowerCase()); Order orderedDish = new Order(menu.getDishFromName(dishName), quantity, decodedTotalOrderCost, isComplete); fillOrderListSize(orderLists, day); orderLists.get(day).addOrder(orderedDish); @@ -234,11 +235,11 @@ private static void decodeSalesData(String orderLine, ArrayList order * @return True if the Dish is valid, false otherwise. */ private static boolean isDishValid(String orderLine, Dish dish) { - if (dish == null) { - ui.showToUser(ErrorMessages.INVALID_ORDER_DATA + orderLine); - return false; + if (dish != null) { + return true; } - return true; + ui.showToUser(ErrorMessages.INVALID_ORDER_DATA + orderLine); + return false; } /** @@ -254,13 +255,23 @@ private static boolean isOrderCostAccurate(String orderLine, Dish dish, int quantity, float decodedTotalOrderCost) { float costOfDish = dish.getPrice(); float expectedTotalOrderCost = quantity * costOfDish; - if (decodedTotalOrderCost != expectedTotalOrderCost) { - String messageToUser = String.format(ErrorMessages.INACCURATE_ORDER_COST_DATA, - orderLine, decodedTotalOrderCost, expectedTotalOrderCost ); - ui.showToUser(messageToUser); - return false; + if (decodedTotalOrderCost == expectedTotalOrderCost) { + return true; } - return true; + String messageToUser = String.format(ErrorMessages.INACCURATE_ORDER_COST_DATA, + orderLine, decodedTotalOrderCost, expectedTotalOrderCost ); + ui.showToUser(messageToUser); + return false; + + } + + private static boolean isCompleteStatusAccurate(String orderLine, String completeStatus) { + if (completeStatus.equalsIgnoreCase("true") + || completeStatus.equalsIgnoreCase("false")) { + return true; + } + ui.showToUser(ErrorMessages.INVALID_ORDER_STATUS + orderLine); + return false; } diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index e6f1c435bf..a0c0f000fa 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -80,6 +80,7 @@ public class ErrorMessages { public static final String INVALID_SALES_DATA = "orders.txt: Invalid format, this order will be removed -> "; public static final String INVALID_ORDER_DATA = "orders.txt: Invalid dish, this order will be removed -> "; + public static final String INVALID_ORDER_STATUS = "orders.txt: Invalid status, this order will be removed -> "; public static final String INACCURATE_ORDER_COST_DATA = "orders.txt: The total order cost of this order -> \"%s\" " + "is inaccurate and will hence be updated from %.2f to %.2f instead."; From c5670150340c4e636ea078382ad7d776e05f1b4e Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 14:09:34 +0800 Subject: [PATCH 09/18] Update error messages for edit_price --- src/main/java/seedu/cafectrl/ui/ErrorMessages.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index a45427dacf..049265cd91 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -14,7 +14,7 @@ public class ErrorMessages { public static final String INVALID_DISH_NAME_LENGTH_MESSAGE = "Error: Your dish name length is too long!\n" + "Please ensure your dish name is less than 35 characters."; public static final String INVALID_INGREDIENT_NAME_LENGTH_MESSAGE = "Error: Your dish name length is too long!"; - public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments " + public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Invalid arguments " + "for edit price command.\n" + EditPriceCommand.MESSAGE_USAGE; public static final String MISSING_ARGUMENT_FOR_LIST_INGREDIENTS = "Error: Missing arguments " @@ -24,12 +24,13 @@ public class ErrorMessages { public static final String INVALID_ARGUMENT_FOR_BUY_INGREDIENT = "Error: Invalid arguments " + "for buy ingredient command."; public static final String WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE = "Something is wrong with " - + "the dish index! Could you make sure that is it of type int \n" - + "and do not type in multiple dish indexes at one time!"; + + "the arguments! The types for dish and price are integer and float respectively, \n" + + "and do not type in duplicated arguments at one time!"; public static final String WRONG_PRICE_TYPE_FOR_EDIT_PRICE = "Error: " + "Invalid price!\n" + "Price must be a float and within the range of " - + "0.00 to 1000000 with up to 2 decimal place"; + + "0.00 to 1000000 with up to 2 decimal place. \n" + + "Special characters such as $ are not allowed!"; public static final String UNKNOWN_COMMAND_MESSAGE = "Error: Unknown command. " + "Type 'help' to view the accepted list of commands"; public static final String INVALID_DISH_INDEX = "Do we even have this dish? " From 765691c785803a12e8a61482feec89f3437f5a40 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 14:25:33 +0800 Subject: [PATCH 10/18] Remove negative sign for price -0.00 --- src/main/java/seedu/cafectrl/data/dish/Dish.java | 6 +++--- src/main/java/seedu/cafectrl/ui/Messages.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/dish/Dish.java b/src/main/java/seedu/cafectrl/data/dish/Dish.java index a110716517..59a7dd0acf 100644 --- a/src/main/java/seedu/cafectrl/data/dish/Dish.java +++ b/src/main/java/seedu/cafectrl/data/dish/Dish.java @@ -12,12 +12,12 @@ public class Dish { public Dish(String name, ArrayList ingredients, float price) { this.name = name; this.ingredients = ingredients; - this.price = price; + this.price = Math.abs(price); } public Dish(String name, float price) { this.name = name; this.ingredients = null; - this.price = price; + this.price = Math.abs(price); } public String getName() { @@ -36,7 +36,7 @@ public String getPriceString() { } public void setPrice(float newPrice) { - this.price = newPrice; + this.price = Math.abs(newPrice); } @Override diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java index b34ac13d3e..d6ba7d487f 100644 --- a/src/main/java/seedu/cafectrl/ui/Messages.java +++ b/src/main/java/seedu/cafectrl/ui/Messages.java @@ -3,7 +3,7 @@ public class Messages { /** Greeting messages */ - public static final String LINE_STRING = "-----------------------------------------------------"; + public static final String LINE_STRING = "----------------------------------------------------------"; public static final String WELCOME_MESSAGE = "Hello! Welcome to CafeCTRL!"; public static final String GOODBYE_MESSAGE = "Goodbye <3 Have a great day ahead!"; From 8b176847164d95d1f2b7f7b4d980475afa1ee6bc Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 14:32:33 +0800 Subject: [PATCH 11/18] Output error message if there is argument after help command --- src/main/java/seedu/cafectrl/parser/Parser.java | 10 +++++++--- src/main/java/seedu/cafectrl/ui/ErrorMessages.java | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index a55c3dde2a..e9421a1b43 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -129,7 +129,7 @@ public Command parseCommand(Menu menu, String userInput, Ui ui, return prepareBuyIngredient(arguments, ui, pantry, menu); case HelpCommand.COMMAND_WORD: - return prepareHelpCommand(ui); + return prepareHelpCommand(ui, arguments); case ExitCommand.COMMAND_WORD: return new ExitCommand(ui, pantry); @@ -571,8 +571,12 @@ public static boolean containsSpecialChar(String text) { } //@@author ziyi105 - private static Command prepareHelpCommand(Ui ui) { - return new HelpCommand(ui); + private static Command prepareHelpCommand(Ui ui, String arguments) { + if (arguments.isEmpty()) { + return new HelpCommand(ui); + } else { + return new IncorrectCommand(ErrorMessages.WRONG_HELP_FORMAT, ui); + } } //@@author Cazh1 diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index 049265cd91..7379bbc017 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -1,6 +1,7 @@ package seedu.cafectrl.ui; import seedu.cafectrl.command.EditPriceCommand; +import seedu.cafectrl.command.HelpCommand; public class ErrorMessages { public static final String INVALID_ADD_DISH_FORMAT_MESSAGE = "Error: Incorrect format for the add command.\n"; @@ -81,4 +82,6 @@ public class ErrorMessages { public static final String NAME_CANNOT_CONTAIN_SPECIAL_CHAR = "Is there a special character" + "in the name?\n I have poor memory and am unable to remember names with special characters" + ",\nso could you remove them?"; + public static final String WRONG_HELP_FORMAT = "Invalid help command format!\n" + + HelpCommand.MESSAGE_USAGE; } From ceb86614afb600545c32d58b5a0dc81e252da32a Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 15:13:17 +0800 Subject: [PATCH 12/18] Use line string to seperate every command in help --- .../command/BuyIngredientCommand.java | 2 +- src/main/java/seedu/cafectrl/ui/Ui.java | 56 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java index dca11230b3..542e9032c5 100644 --- a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java +++ b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java @@ -17,7 +17,7 @@ */ public class BuyIngredientCommand extends Command { public static final String COMMAND_WORD = "buy_ingredient"; - public static final String MESSAGE_USAGE = "\nTo buy ingredient:\n" + public static final String MESSAGE_USAGE = "To buy ingredient:\n" + COMMAND_WORD + " ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY" + "[, ingredient/INGREDIENT2_NAME, qty/INGREDIENT2_QTY...]\n" + "Example:" diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java index 673f92903a..da30ba1a85 100644 --- a/src/main/java/seedu/cafectrl/ui/Ui.java +++ b/src/main/java/seedu/cafectrl/ui/Ui.java @@ -1,18 +1,6 @@ package seedu.cafectrl.ui; -import seedu.cafectrl.command.AddDishCommand; -import seedu.cafectrl.command.AddOrderCommand; -import seedu.cafectrl.command.BuyIngredientCommand; -import seedu.cafectrl.command.DeleteDishCommand; -import seedu.cafectrl.command.EditPriceCommand; -import seedu.cafectrl.command.ExitCommand; -import seedu.cafectrl.command.HelpCommand; -import seedu.cafectrl.command.ListIngredientCommand; -import seedu.cafectrl.command.ListMenuCommand; -import seedu.cafectrl.command.NextDayCommand; -import seedu.cafectrl.command.PreviousDayCommand; -import seedu.cafectrl.command.ListSaleByDayCommand; -import seedu.cafectrl.command.ViewTotalStockCommand; +import seedu.cafectrl.command.*; import seedu.cafectrl.data.dish.Dish; import seedu.cafectrl.data.dish.Ingredient; @@ -139,20 +127,27 @@ public void showEditPriceMessage(String menuItem) { public void showHelp() { showToUserWithSpaceBetweenLines(Messages.LIST_OF_COMMANDS, - Messages.INSTRUCTION_ON_COMMAND_FORMAT, - AddDishCommand.MESSAGE_USAGE, - AddOrderCommand.MESSAGE_USAGE, - BuyIngredientCommand.MESSAGE_USAGE, - DeleteDishCommand.MESSAGE_USAGE, - EditPriceCommand.MESSAGE_USAGE, - ExitCommand.MESSAGE_USAGE, - HelpCommand.MESSAGE_USAGE, - ListIngredientCommand.MESSAGE_USAGE, - ListMenuCommand.MESSAGE_USAGE, - NextDayCommand.MESSAGE_USAGE, - PreviousDayCommand.MESSAGE_USAGE, - ViewTotalStockCommand.MESSAGE_USAGE, - ListSaleByDayCommand.MESSAGE_USAGE); + Messages.INSTRUCTION_ON_COMMAND_FORMAT); + + showToUser(Messages.LINE_STRING); + ArrayList usagesTexts = new ArrayList<>(); + + usagesTexts.add(ExitCommand.MESSAGE_USAGE); + usagesTexts.add(HelpCommand.MESSAGE_USAGE); + usagesTexts.add(AddDishCommand.MESSAGE_USAGE); + usagesTexts.add(DeleteDishCommand.MESSAGE_USAGE); + usagesTexts.add(EditPriceCommand.MESSAGE_USAGE); + usagesTexts.add(ListMenuCommand.MESSAGE_USAGE); + usagesTexts.add(ListIngredientCommand.MESSAGE_USAGE); + usagesTexts.add(BuyIngredientCommand.MESSAGE_USAGE); + usagesTexts.add(ViewTotalStockCommand.MESSAGE_USAGE); + usagesTexts.add(AddOrderCommand.MESSAGE_USAGE); + usagesTexts.add(ListTotalSalesCommand.MESSAGE_USAGE); + usagesTexts.add(ListSaleByDayCommand.MESSAGE_USAGE); + usagesTexts.add(NextDayCommand.MESSAGE_USAGE); + usagesTexts.add(PreviousDayCommand.MESSAGE_USAGE); + + showToUserWithSpaceBetweenLines(usagesTexts); } public void showToUserWithSpaceBetweenLines(String... message) { @@ -161,6 +156,13 @@ public void showToUserWithSpaceBetweenLines(String... message) { } } + public void showToUserWithSpaceBetweenLines(ArrayList message) { + for (String m: message) { + System.out.println(m); + System.out.println(Messages.LINE_STRING); + } + } + public void showDishAvailability(int numberOfDishes){ showToUser("Available Dishes: " + numberOfDishes); } From fc12dbf84acce60dbc4b48d519bb48cddf6828ee Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 15:24:33 +0800 Subject: [PATCH 13/18] Remove wildcard import --- src/main/java/seedu/cafectrl/ui/Ui.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java index da30ba1a85..0e380ad140 100644 --- a/src/main/java/seedu/cafectrl/ui/Ui.java +++ b/src/main/java/seedu/cafectrl/ui/Ui.java @@ -1,6 +1,19 @@ package seedu.cafectrl.ui; -import seedu.cafectrl.command.*; +import seedu.cafectrl.command.AddDishCommand; +import seedu.cafectrl.command.AddOrderCommand; +import seedu.cafectrl.command.BuyIngredientCommand; +import seedu.cafectrl.command.DeleteDishCommand; +import seedu.cafectrl.command.EditPriceCommand; +import seedu.cafectrl.command.ExitCommand; +import seedu.cafectrl.command.HelpCommand; +import seedu.cafectrl.command.ListIngredientCommand; +import seedu.cafectrl.command.ListMenuCommand; +import seedu.cafectrl.command.ListSaleByDayCommand; +import seedu.cafectrl.command.ListTotalSalesCommand; +import seedu.cafectrl.command.NextDayCommand; +import seedu.cafectrl.command.PreviousDayCommand; +import seedu.cafectrl.command.ViewTotalStockCommand; import seedu.cafectrl.data.dish.Dish; import seedu.cafectrl.data.dish.Ingredient; From 1b8b737b4bb0e2b56ed511ba64f3ceafa8712eb1 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 15:36:16 +0800 Subject: [PATCH 14/18] Remove HelpCommandTest --- .../cafectrl/command/HelpCommandTest.java | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 src/test/java/seedu/cafectrl/command/HelpCommandTest.java diff --git a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java deleted file mode 100644 index 9f93081ed7..0000000000 --- a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package seedu.cafectrl.command; - -import org.junit.jupiter.api.Test; -import seedu.cafectrl.data.Menu; -import seedu.cafectrl.ui.Messages; -import seedu.cafectrl.ui.Ui; - -import java.util.ArrayList; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class HelpCommandTest { - - @Test - void execute_validInput_displayHelp() { - - ArrayList actualOutputs = new ArrayList<>(); - Menu menu = new Menu(); - Ui ui = new Ui() { - @Override - public void showToUser(String... message) { - actualOutputs.addAll(Arrays.asList(message)); - } - - @Override - public void showToUserWithSpaceBetweenLines(String... message) { - actualOutputs.addAll(Arrays.asList(message)); - } - }; - - HelpCommand helpCommand = new HelpCommand(ui); - helpCommand.execute(); - - ArrayList expectedOutputs = new ArrayList<>(); - - expectedOutputs.add(Messages.LINE_STRING); - expectedOutputs.add(Messages.LIST_OF_COMMANDS); - expectedOutputs.add(Messages.INSTRUCTION_ON_COMMAND_FORMAT); - expectedOutputs.add(AddDishCommand.MESSAGE_USAGE); - expectedOutputs.add(AddOrderCommand.MESSAGE_USAGE); - expectedOutputs.add(BuyIngredientCommand.MESSAGE_USAGE); - expectedOutputs.add(DeleteDishCommand.MESSAGE_USAGE); - expectedOutputs.add(EditPriceCommand.MESSAGE_USAGE); - expectedOutputs.add(ExitCommand.MESSAGE_USAGE); - expectedOutputs.add(HelpCommand.MESSAGE_USAGE); - expectedOutputs.add(ListIngredientCommand.MESSAGE_USAGE); - expectedOutputs.add(ListMenuCommand.MESSAGE_USAGE); - expectedOutputs.add(NextDayCommand.MESSAGE_USAGE); - expectedOutputs.add(PreviousDayCommand.MESSAGE_USAGE); - expectedOutputs.add(ViewTotalStockCommand.MESSAGE_USAGE); - expectedOutputs.add(ListSaleByDayCommand.MESSAGE_USAGE); - - for (int i = 0; i < expectedOutputs.size(); i++) { - assertEquals(expectedOutputs.get(i), actualOutputs.get(i)); - } - } -} From 47c74adbe10049f97e58f117129a7965799345a0 Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 16:30:56 +0800 Subject: [PATCH 15/18] Edit decode sales function according to PR review comments. --- .../java/seedu/cafectrl/data/OrderList.java | 10 +++++----- .../java/seedu/cafectrl/data/dish/Dish.java | 2 +- .../java/seedu/cafectrl/storage/Decoder.java | 18 ++++++++++-------- .../java/seedu/cafectrl/storage/Encoder.java | 1 + .../java/seedu/cafectrl/ui/ErrorMessages.java | 3 ++- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/OrderList.java b/src/main/java/seedu/cafectrl/data/OrderList.java index 73879ef836..91b357cfb9 100644 --- a/src/main/java/seedu/cafectrl/data/OrderList.java +++ b/src/main/java/seedu/cafectrl/data/OrderList.java @@ -63,7 +63,7 @@ public void printOrderList(Menu menu, Ui ui) { ui.showSalesAll(aggregatedOrder.getDishName(), aggregatedOrder.getQuantity(), - dollarValue.format(aggregatedOrder.calculateTotalOrderCost())); + dollarValue.format(calculateTotalCost(aggregatedOrders))); } ui.showSalesBottom(); @@ -80,10 +80,10 @@ private void aggregateOrder(Order order, ArrayList aggregatedOrders) { logger.info("Aggregating order..."); if (order.getIsComplete()) { int index = getIndexByDishName(aggregatedOrders, order.getDishName()); - aggregatedOrders.get(index).setQuantity(aggregatedOrders.get(index).getQuantity() - + order.getQuantity()); - aggregatedOrders.get(index).setTotalOrderCost(aggregatedOrders.get(index).getTotalOrderCost() - + order.getTotalOrderCost()); + aggregatedOrders.get(index) + .setQuantity(aggregatedOrders.get(index).getQuantity() + order.getQuantity()); + aggregatedOrders.get(index) + .setTotalOrderCost(aggregatedOrders.get(index).getTotalOrderCost() + order.getTotalOrderCost()); } } diff --git a/src/main/java/seedu/cafectrl/data/dish/Dish.java b/src/main/java/seedu/cafectrl/data/dish/Dish.java index a110716517..0495d8d0ba 100644 --- a/src/main/java/seedu/cafectrl/data/dish/Dish.java +++ b/src/main/java/seedu/cafectrl/data/dish/Dish.java @@ -16,7 +16,7 @@ public Dish(String name, ArrayList ingredients, float price) { } public Dish(String name, float price) { this.name = name; - this.ingredients = null; + this.ingredients = new ArrayList<>(); this.price = price; } diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 370fed6eec..4d74f6bb6b 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -205,24 +205,27 @@ private static void decodeSalesData(String orderLine, ArrayList order //@@author int quantity = Integer.parseInt(orderData[2].trim()); - float decodedTotalOrderCost = Float.parseFloat(orderData[3].trim()); - String completeStatus = orderData[4].trim(); + float decodedDishPrice = Float.parseFloat(orderData[3].trim()); + float decodedTotalOrderCost = Float.parseFloat(orderData[4].trim()); + String completeStatus = orderData[5].trim(); Dish dish = menu.getDishFromName(dishName); boolean isDataAccurate = isDishValid(orderLine, dish) - && isOrderCostAccurate(orderLine, dish, quantity, decodedTotalOrderCost) + && isOrderCostAccurate(orderLine, quantity, decodedDishPrice, decodedTotalOrderCost) && isCompleteStatusAccurate(orderLine, completeStatus); if (!isDataAccurate) { return; } + Dish dishToAdd = new Dish(dishName, decodedDishPrice); //creates new order and adds to orderList for specific day boolean isComplete = Boolean.parseBoolean(completeStatus.toLowerCase()); - Order orderedDish = new Order(menu.getDishFromName(dishName), quantity, decodedTotalOrderCost, isComplete); + Order orderedDish = new Order(dishToAdd, quantity, decodedTotalOrderCost, isComplete); fillOrderListSize(orderLists, day); orderLists.get(day).addOrder(orderedDish); } catch (Exception e) { logger.log(Level.WARNING, "Line corrupted: " + e.getMessage(), e); + System.out.println(e.getMessage()); ui.showToUser(ErrorMessages.INVALID_SALES_DATA + orderLine); } } @@ -251,10 +254,9 @@ private static boolean isDishValid(String orderLine, Dish dish) { * @param decodedTotalOrderCost The decoded total order cost from the order line. * @return True if the decoded total order cost matches the expected total order cost, false otherwise. */ - private static boolean isOrderCostAccurate(String orderLine, Dish dish, - int quantity, float decodedTotalOrderCost) { - float costOfDish = dish.getPrice(); - float expectedTotalOrderCost = quantity * costOfDish; + private static boolean isOrderCostAccurate(String orderLine, int quantity, + float decodedDishPrice, float decodedTotalOrderCost) { + float expectedTotalOrderCost = quantity * decodedDishPrice; if (decodedTotalOrderCost == expectedTotalOrderCost) { return true; } diff --git a/src/main/java/seedu/cafectrl/storage/Encoder.java b/src/main/java/seedu/cafectrl/storage/Encoder.java index d8b11e2de8..59d4d33030 100644 --- a/src/main/java/seedu/cafectrl/storage/Encoder.java +++ b/src/main/java/seedu/cafectrl/storage/Encoder.java @@ -135,6 +135,7 @@ public static ArrayList encodeSales(Sales sales) { orderString.append((day + 1) + DIVIDER); orderString.append(order.getDishName() + DIVIDER); orderString.append(order.getQuantity() + DIVIDER); + orderString.append(order.getOrderedDish().getPrice() + DIVIDER); orderString.append(order.calculateTotalOrderCost() + DIVIDER); orderString.append(order.getIsComplete()); orderString.append(System.lineSeparator()); diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index a0c0f000fa..e04a439a6d 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -79,7 +79,8 @@ public class ErrorMessages { public static final String INVALID_MENU_DATA = "menu.txt: Invalid format, this dish will be removed -> "; public static final String INVALID_SALES_DATA = "orders.txt: Invalid format, this order will be removed -> "; - public static final String INVALID_ORDER_DATA = "orders.txt: Invalid dish, this order will be removed -> "; + public static final String INVALID_ORDER_DATA = "orders.txt: Dish is not in current menu, " + + "this order will be removed -> "; public static final String INVALID_ORDER_STATUS = "orders.txt: Invalid status, this order will be removed -> "; public static final String INACCURATE_ORDER_COST_DATA = "orders.txt: The total order cost of this order -> \"%s\" " + "is inaccurate and will hence be updated from %.2f to %.2f instead."; From bcd4781b5ed0082a575abaadd1a0b11787cc5b9f Mon Sep 17 00:00:00 2001 From: NaychiMin Date: Sun, 12 Nov 2023 17:02:03 +0800 Subject: [PATCH 16/18] Edit decoding of sales.txt to fix bug related to showing total order cost. --- .../java/seedu/cafectrl/data/OrderList.java | 2 +- .../java/seedu/cafectrl/storage/Decoder.java | 32 +++---------------- .../java/seedu/cafectrl/storage/Encoder.java | 1 - .../ListTotalSalesCommandCommandTest.java | 2 +- 4 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/OrderList.java b/src/main/java/seedu/cafectrl/data/OrderList.java index 91b357cfb9..f38bb3ef81 100644 --- a/src/main/java/seedu/cafectrl/data/OrderList.java +++ b/src/main/java/seedu/cafectrl/data/OrderList.java @@ -63,7 +63,7 @@ public void printOrderList(Menu menu, Ui ui) { ui.showSalesAll(aggregatedOrder.getDishName(), aggregatedOrder.getQuantity(), - dollarValue.format(calculateTotalCost(aggregatedOrders))); + dollarValue.format(aggregatedOrder.getTotalOrderCost())); } ui.showSalesBottom(); diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 4d74f6bb6b..de64614b93 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -202,16 +202,14 @@ private static void decodeSalesData(String orderLine, ArrayList order fillOrderListSize(orderLists, day); return; } - //@@author int quantity = Integer.parseInt(orderData[2].trim()); float decodedDishPrice = Float.parseFloat(orderData[3].trim()); - float decodedTotalOrderCost = Float.parseFloat(orderData[4].trim()); - String completeStatus = orderData[5].trim(); - Dish dish = menu.getDishFromName(dishName); + String completeStatus = orderData[4].trim(); + float totalOrderCost = quantity * decodedDishPrice; + Dish dish = menu.getDishFromName(dishName); boolean isDataAccurate = isDishValid(orderLine, dish) - && isOrderCostAccurate(orderLine, quantity, decodedDishPrice, decodedTotalOrderCost) && isCompleteStatusAccurate(orderLine, completeStatus); if (!isDataAccurate) { return; @@ -220,7 +218,7 @@ && isOrderCostAccurate(orderLine, quantity, decodedDishPrice, decodedTotalOrderC Dish dishToAdd = new Dish(dishName, decodedDishPrice); //creates new order and adds to orderList for specific day boolean isComplete = Boolean.parseBoolean(completeStatus.toLowerCase()); - Order orderedDish = new Order(dishToAdd, quantity, decodedTotalOrderCost, isComplete); + Order orderedDish = new Order(dishToAdd, quantity, totalOrderCost, isComplete); fillOrderListSize(orderLists, day); orderLists.get(day).addOrder(orderedDish); } catch (Exception e) { @@ -245,28 +243,6 @@ private static boolean isDishValid(String orderLine, Dish dish) { return false; } - /** - * Checks if the decoded total order cost matches the expected total order cost and shows an error message if not. - * - * @param orderLine The order line in the format "day|dishName|quantity|totalOrderCost|isComplete". - * @param dish The Dish object in the order. - * @param quantity The quantity of the dish in the order. - * @param decodedTotalOrderCost The decoded total order cost from the order line. - * @return True if the decoded total order cost matches the expected total order cost, false otherwise. - */ - private static boolean isOrderCostAccurate(String orderLine, int quantity, - float decodedDishPrice, float decodedTotalOrderCost) { - float expectedTotalOrderCost = quantity * decodedDishPrice; - if (decodedTotalOrderCost == expectedTotalOrderCost) { - return true; - } - String messageToUser = String.format(ErrorMessages.INACCURATE_ORDER_COST_DATA, - orderLine, decodedTotalOrderCost, expectedTotalOrderCost ); - ui.showToUser(messageToUser); - return false; - - } - private static boolean isCompleteStatusAccurate(String orderLine, String completeStatus) { if (completeStatus.equalsIgnoreCase("true") || completeStatus.equalsIgnoreCase("false")) { diff --git a/src/main/java/seedu/cafectrl/storage/Encoder.java b/src/main/java/seedu/cafectrl/storage/Encoder.java index 59d4d33030..ce1704976e 100644 --- a/src/main/java/seedu/cafectrl/storage/Encoder.java +++ b/src/main/java/seedu/cafectrl/storage/Encoder.java @@ -136,7 +136,6 @@ public static ArrayList encodeSales(Sales sales) { orderString.append(order.getDishName() + DIVIDER); orderString.append(order.getQuantity() + DIVIDER); orderString.append(order.getOrderedDish().getPrice() + DIVIDER); - orderString.append(order.calculateTotalOrderCost() + DIVIDER); orderString.append(order.getIsComplete()); orderString.append(System.lineSeparator()); encodedList.add(String.valueOf(orderString)); diff --git a/src/test/java/seedu/cafectrl/command/ListTotalSalesCommandCommandTest.java b/src/test/java/seedu/cafectrl/command/ListTotalSalesCommandCommandTest.java index 9b70079f05..0469d9ed20 100644 --- a/src/test/java/seedu/cafectrl/command/ListTotalSalesCommandCommandTest.java +++ b/src/test/java/seedu/cafectrl/command/ListTotalSalesCommandCommandTest.java @@ -53,7 +53,7 @@ public void execute_existingSales_listTotalSales() { Order order4 = new Order(dishChickenChop, 1); order4.setComplete(true); Order order5 = new Order(dishChickenChop, 1); - order5.setComplete(true); + order5.setComplete(true); // Create a dummy order list for day 3 OrderList orderList3 = new OrderList(); From 1efa576d109344b84d4fda5deb4ef4677b1f6f04 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Sun, 12 Nov 2023 17:03:33 +0800 Subject: [PATCH 17/18] Check the length of the ingredient name when decoding pantry_stock.txt --- src/main/java/seedu/cafectrl/storage/Decoder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index eca5d40f06..a12653be4f 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -31,6 +31,7 @@ public class Decoder { private static final String INGREDIENT_DIVIDER = " - "; private static final Ui ui = new Ui(); private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + //@@author ShaniceTang /** * Decodes an ArrayList of string lines into a Menu object, reconstructing its content. @@ -125,6 +126,7 @@ public static Pantry decodePantryStockData(ArrayList encodedPantryStock) // Check whether the parameters are correct if (!Parser.containsSpecialChar(ingredientName) + && !Parser.isNameLengthInvalid(ingredientName) && !Parser.isRepeatedIngredientName(ingredientName, pantryStock) && !Parser.isInvalidQty(qty) && !Parser.isEmptyUnit(unit) @@ -226,5 +228,4 @@ private static ArrayList fillOrderListSize(ArrayList order } return orderLists; } - } From 6e79d3b20687aae3c4c37c28cbffa13ed591fcac Mon Sep 17 00:00:00 2001 From: Cazh1 <82131563+Cazh1@users.noreply.github.com> Date: Sun, 12 Nov 2023 17:06:21 +0800 Subject: [PATCH 18/18] Update ListTotalSalesCommandCommandTest.java --- .../cafectrl/command/ListTotalSalesCommandCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/seedu/cafectrl/command/ListTotalSalesCommandCommandTest.java b/src/test/java/seedu/cafectrl/command/ListTotalSalesCommandCommandTest.java index 0469d9ed20..9b70079f05 100644 --- a/src/test/java/seedu/cafectrl/command/ListTotalSalesCommandCommandTest.java +++ b/src/test/java/seedu/cafectrl/command/ListTotalSalesCommandCommandTest.java @@ -53,7 +53,7 @@ public void execute_existingSales_listTotalSales() { Order order4 = new Order(dishChickenChop, 1); order4.setComplete(true); Order order5 = new Order(dishChickenChop, 1); - order5.setComplete(true); + order5.setComplete(true); // Create a dummy order list for day 3 OrderList orderList3 = new OrderList();