diff --git a/docs/images/aboutUs/dexter.jpg b/docs/images/aboutUs/dexter.jpg index b582d26154..0e1723d073 100644 Binary files a/docs/images/aboutUs/dexter.jpg and b/docs/images/aboutUs/dexter.jpg differ diff --git a/src/main/java/seedu/cafectrl/data/Chef.java b/src/main/java/seedu/cafectrl/data/Chef.java index 7f00f122f6..c55d722973 100644 --- a/src/main/java/seedu/cafectrl/data/Chef.java +++ b/src/main/java/seedu/cafectrl/data/Chef.java @@ -6,7 +6,6 @@ import java.util.logging.Level; import java.util.logging.Logger; - public class Chef { private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Order order; diff --git a/src/main/java/seedu/cafectrl/data/Order.java b/src/main/java/seedu/cafectrl/data/Order.java index 3904bd0400..157aae43d2 100644 --- a/src/main/java/seedu/cafectrl/data/Order.java +++ b/src/main/java/seedu/cafectrl/data/Order.java @@ -96,6 +96,7 @@ public void setQuantity(int quantity) { public void setTotalOrderCost(float cost) { this.totalOrderCost = cost; } + public Dish getOrderedDish() { return orderedDish; } diff --git a/src/main/java/seedu/cafectrl/data/OrderList.java b/src/main/java/seedu/cafectrl/data/OrderList.java index 3e56f7bf1a..3b99f08c7d 100644 --- a/src/main/java/seedu/cafectrl/data/OrderList.java +++ b/src/main/java/seedu/cafectrl/data/OrderList.java @@ -13,7 +13,6 @@ */ public class OrderList { private static final DecimalFormat dollarValue = new DecimalFormat("0.00"); - private static final String HEADER_FORMAT = "%-20s %-10s %-20s\n"; private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private ArrayList orderList; private float totalOrderListCost; diff --git a/src/main/java/seedu/cafectrl/data/dish/Dish.java b/src/main/java/seedu/cafectrl/data/dish/Dish.java index 3921eaa5a3..b774fee6f7 100644 --- a/src/main/java/seedu/cafectrl/data/dish/Dish.java +++ b/src/main/java/seedu/cafectrl/data/dish/Dish.java @@ -32,6 +32,7 @@ public ArrayList getIngredients() { public float getPrice() { return price; } + public String getPriceString() { return this.dollarValue.format(this.price); } diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index 7218a6ded1..ab65d4db4c 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -56,7 +56,7 @@ public class Parser implements ParserUtil { + "qty/\\s*(?.*)\\s*"; private static final String INGREDIENT_NAME_REGEX_GROUP_LABEL = "ingredientName"; private static final String INGREDIENT_QTY_REGEX_GROUP_LABEL = "ingredientQty"; - private static final String INGREDIENT_QTY_FORMAT_REGEX = "^\\s*(?[0-9]*)\\s*(?[a-zA-z]*)\\s*$"; + private static final String INGREDIENT_QTY_FORMAT_REGEX = "^\\s*(?[+-]*[0-9]*)\\s*(?[a-zA-z]*)\\s*$"; private static final String INGREDIENT_QTY_VALUE_REGEX_GROUP_LABEL = "value"; private static final String INGREDIENT_QTY_UNIT_REGEX_GROUP_LABEL = "unit"; private static final String ADD_DISH_NAME_ARGUMENT = "name/"; @@ -68,8 +68,7 @@ public class Parser implements ParserUtil { /** Add Order Command Handler Patterns*/ private static final int DISH_NAME_MATCHER_GROUP_NUM = 1; private static final int ORDER_QTY_MATCHER_GROUP_NUM = 2; - private static final String ADD_ORDER_ARGUMENT_STRING = "name/([A-Za-z0-9\\s]+) " - + "qty/([A-Za-z0-9\\s]+)"; + private static final String ADD_ORDER_ARGUMENT_STRING = "name/(.*) qty/(.*)"; /** The rest of Command Handler Patterns*/ @@ -250,11 +249,11 @@ private static Command prepareAdd(String arguments, Menu menu, Ui ui) { // To retrieve specific arguments from arguments //the dishName needs .trim() because the regex accepts whitespaces in the "name/" argument - String dishName = matcher.group(DISH_NAME_MATCHER_GROUP_LABEL).trim(); + String dishName = matcher.group(DISH_NAME_MATCHER_GROUP_LABEL).trim().toLowerCase(); float dishPrice = parsePriceToFloat(matcher.group(PRICE_MATCHER_GROUP_LABEL)); String ingredientsListString = matcher.group(INGREDIENTS_MATCHER_GROUP_LABEL); - detectErrorPostDishNameParse(dishName, menu); + detectErrorPostDishNameParse(dishName, menu, true); ArrayList ingredients = parseIngredients(ingredientsListString, true, menu); Dish dish = new Dish(dishName, ingredients, dishPrice); @@ -293,14 +292,15 @@ private static Matcher detectErrorInPreAddParse(String arguments) throws ParserE return matcher; } - private static void detectErrorPostDishNameParse(String dishName, Menu menu) throws ParserException { + private static void detectErrorPostDishNameParse(String dishName, Menu menu, boolean isCheckRepeatedDishName) + throws ParserException { if (dishName.isEmpty()) { logger.warning("Dish name empty!"); throw new ParserException(ErrorMessages.MISSING_DISH_NAME); } else if (isNameLengthInvalid(dishName)) { logger.warning("Invalid name length!"); throw new ParserException(ErrorMessages.INVALID_DISH_NAME_LENGTH_MESSAGE); - } else if (isRepeatedDishName(dishName, menu)) { + } else if (isCheckRepeatedDishName && isRepeatedDishName(dishName, menu)) { logger.warning("Repeated dish!"); throw new ParserException(ErrorMessages.REPEATED_DISH_MESSAGE); } else if (containsSpecialChar(dishName)) { @@ -346,7 +346,7 @@ private static void parseIngredient( throws ParserException { Matcher ingredientMatcher = detectErrorPreIngredientParse(inputIngredient); - String ingredientName = ingredientMatcher.group(INGREDIENT_NAME_REGEX_GROUP_LABEL).trim(); + String ingredientName = ingredientMatcher.group(INGREDIENT_NAME_REGEX_GROUP_LABEL).trim().toLowerCase(); //ingredientQtyString contains the input text after the "qty/" argument String ingredientQtyString = ingredientMatcher.group(INGREDIENT_QTY_REGEX_GROUP_LABEL).trim(); @@ -769,8 +769,10 @@ private static Command prepareOrder(Menu menu, String arguments, Ui ui, try { // To retrieve specific arguments from arguments - String dishName = matcher.group(DISH_NAME_MATCHER_GROUP_NUM); - int dishQty = Integer.parseInt(matcher.group(ORDER_QTY_MATCHER_GROUP_NUM)); + String dishName = matcher.group(DISH_NAME_MATCHER_GROUP_NUM).trim(); + int dishQty = parseQtyToInt(matcher.group(ORDER_QTY_MATCHER_GROUP_NUM).trim()); + + detectErrorPostDishNameParse(dishName, menu, false); Dish orderedDish = menu.getDishFromName(dishName); if (orderedDish == null) { @@ -780,6 +782,10 @@ private static Command prepareOrder(Menu menu, String arguments, Ui ui, Order order = new Order(orderedDish, dishQty); return new AddOrderCommand(order, ui, pantry, orderList, menu); + } catch (ParserException e) { + return new IncorrectCommand(e.getMessage(), ui); + } catch (NumberFormatException e) { + return new IncorrectCommand(ErrorMessages.INVALID_INT_ORDER_QTY, ui); } catch (Exception e) { return new IncorrectCommand(ErrorMessages.INVALID_ADD_ORDER_FORMAT_MESSAGE + AddOrderCommand.MESSAGE_USAGE + e.getMessage(), ui); @@ -813,6 +819,33 @@ private static Command prepareNextDay(Ui ui, Sales sales, CurrentDate currentDat return new NextDayCommand(ui, sales, currentDate); } + //@@author DextheChik3n + /** + * Parses the quantity text string into integer and checks if the input is valid + * + * @param qtyText text that consist of the order dish quantity + * @return int value of the quantity + * @throws ParserException if the input string does not match the constraints + */ + public static int parseQtyToInt(String qtyText) throws ParserException { + if (qtyText.isEmpty()) { + throw new ParserException(ErrorMessages.MISSING_ORDER_QTY); + } + + int dishQty = Integer.parseInt(qtyText); + + int maxDishQty = 10000; + int minDishQty = 1; + + if (dishQty < minDishQty) { + throw new ParserException(ErrorMessages.BELOW_MIN_ORDER_QTY); + } else if (dishQty > maxDishQty) { + throw new ParserException(ErrorMessages.EXCEED_MAX_ORDER_QTY); + } + + return dishQty; + } + //@@author NaychiMin /** * Prepares a command to display all sales items. diff --git a/src/main/java/seedu/cafectrl/storage/CorruptedDataException.java b/src/main/java/seedu/cafectrl/storage/CorruptedDataException.java deleted file mode 100644 index 73c5f86877..0000000000 --- a/src/main/java/seedu/cafectrl/storage/CorruptedDataException.java +++ /dev/null @@ -1,4 +0,0 @@ -package seedu.cafectrl.storage; - -public class CorruptedDataException extends Exception { -} diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 939c0ddbaf..47c21be8ec 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -26,11 +26,35 @@ * Pantry stock, and OrderList, allowing retrieval of data stored in a file. */ public class Decoder { - + private static final Ui ui = new Ui(); + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private static final String DIVIDER = "\\| "; private static final String INGREDIENT_DIVIDER = " - "; - private static final Ui ui = new Ui(); - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + + /** For menu decoder */ + private static final int MAX_INGREDIENTS_STRING_ARRAY_SIZE = 1; + private static final int DISH_NAME_INDEX_DISH_ARRAY = 0; + private static final int DISH_PRICE_INDEX_DISH_ARRAY = 1; + private static final int DISH_INGREDIENT_START_INDEX = 2; + private static final int NAME_INDEX_INGREDIENT_ARRAY = 0; + private static final int QTY_INDEX_INGREDIENT_ARRAY = 1; + private static final int UNIT_INDEX_INGREDIENT_ARRAY = 2; + + /** for stock pantry decoder */ + private static final int NAME_INDEX_PANTRY = 0; + private static final int QTY_INDEX_PANTRY = 1; + private static final int UNIT_INDEX_PANTRY = 2; + private static final int MAX_PANTRY_ARRAY_SIZE = 3; + + /** for sales decoder */ + private static final int DAY_INDEX_SALES = 0; + private static final int DISH_NAME_INDEX_SALES = 1; + private static final int QTY_INDEX_SALES = 2; + private static final int DISH_PRICE_INDEX_SALES = 3; + private static final int STATUS_INDEX_SALES = 4; + private static final String TRUE_STRING = "true"; + private static final String FALSE_STRING = "false"; + private static final int MIN_DISH_PRICE = 0; //@@author ShaniceTang /** @@ -61,11 +85,15 @@ private static void decodeDishString(String dishString, ArrayList menuDish String dishName = ""; try { String[] dishStringArray = dishString.split(DIVIDER); - dishName = dishStringArray[0].trim().toLowerCase(); + dishName = dishStringArray[DISH_NAME_INDEX_DISH_ARRAY].trim().toLowerCase(); + checkNameValidity(dishName); - float dishPrice = Parser.parsePriceToFloat(dishStringArray[1]); - String[] ingredientStringArray = Arrays.copyOfRange(dishStringArray, 2, dishStringArray.length); + + float dishPrice = Parser.parsePriceToFloat(dishStringArray[DISH_PRICE_INDEX_DISH_ARRAY]); + String[] ingredientStringArray = Arrays.copyOfRange( + dishStringArray, DISH_INGREDIENT_START_INDEX, dishStringArray.length); ArrayList ingredientsList = decodeIngredientData(ingredientStringArray); + menuDishList.add(new Dish(dishName, ingredientsList, dishPrice)); } catch (ParserException e) { logger.log(Level.WARNING, "Dish has invalid price: " + e.getMessage(), e); @@ -94,19 +122,23 @@ private static void checkNameValidity(String name) throws Exception { private static ArrayList decodeIngredientData(String[] ingredientsStringArray) throws Exception { ArrayList ingredientList = new ArrayList<>(); - if (ingredientsStringArray.length < 1) { + if (ingredientsStringArray.length < MAX_INGREDIENTS_STRING_ARRAY_SIZE) { throw new RuntimeException(ErrorMessages.MISSING_INGREDIENT_MENU_DATA); } for(String ingredientString : ingredientsStringArray) { logger.info("Ingredient to decode: " + ingredientString); + String[] array = ingredientString.split(INGREDIENT_DIVIDER); - String name = array[0].trim().toLowerCase(); + String name = array[NAME_INDEX_INGREDIENT_ARRAY].trim().toLowerCase(); checkNameValidity(name); - int qty = Integer.parseInt(array[1].trim()); + + int qty = Integer.parseInt(array[QTY_INDEX_INGREDIENT_ARRAY].trim()); checkQtyValidity(qty); - String unit = array[2].trim(); + + String unit = array[UNIT_INDEX_INGREDIENT_ARRAY].trim(); checkUnitValidity(unit); + ingredientList.add(new Ingredient(name, qty, unit)); } return ingredientList; @@ -146,9 +178,9 @@ public static Pantry decodePantryStockData(ArrayList encodedPantryStock) ui.showToUser(ErrorMessages.ERROR_IN_PANTRY_STOCK_DATA + encodedData); continue; } - String ingredientName = decodedData[0].trim(); - String qtyText = decodedData[1].trim(); - String unit = decodedData[2].trim(); + String ingredientName = decodedData[NAME_INDEX_PANTRY].trim().toLowerCase(); + String qtyText = decodedData[QTY_INDEX_PANTRY].trim(); + String unit = decodedData[UNIT_INDEX_PANTRY].trim(); // Check whether qty is an integer int qty; @@ -200,11 +232,11 @@ private static boolean isValidUnit(String unit) { * @return true if the format is correct, false otherwise */ private static boolean isValidPantryStockFormat(String[] decodedPantryStock) { - if (decodedPantryStock.length != 3) { + if (decodedPantryStock.length != MAX_PANTRY_ARRAY_SIZE) { return false; } else { try { - Integer.parseInt(decodedPantryStock[1].trim()); + Integer.parseInt(decodedPantryStock[QTY_INDEX_PANTRY].trim()); } catch (NumberFormatException e) { return false; } @@ -254,8 +286,8 @@ public static Sales decodeSales(ArrayList textLines, Menu menu) { 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(); + int day = Integer.parseInt(orderData[DAY_INDEX_SALES].trim()) - Sales.DAY_DISPLAY_OFFSET; + String dishName = orderData[DISH_NAME_INDEX_SALES].trim().toLowerCase(); //@@author Cazh1 //keeps track of the number of days cafe has been operating for @@ -265,9 +297,9 @@ private static void decodeSalesData(String orderLine, ArrayList order } //@@author - int quantity = Integer.parseInt(orderData[2].trim()); - float decodedDishPrice = Float.parseFloat(orderData[3].trim()); - String completeStatus = orderData[4].trim(); + int quantity = Integer.parseInt(orderData[QTY_INDEX_SALES].trim()); + float decodedDishPrice = Float.parseFloat(orderData[DISH_PRICE_INDEX_SALES].trim()); + String completeStatus = orderData[STATUS_INDEX_SALES].trim(); float totalOrderCost = quantity * decodedDishPrice; checkNameValidity(dishName); @@ -291,8 +323,8 @@ && isValidQty(orderLine, quantity) } private static boolean isCompleteStatusAccurate(String orderLine, String completeStatus) { - if (completeStatus.equalsIgnoreCase("true") - || completeStatus.equalsIgnoreCase("false")) { + if (completeStatus.equalsIgnoreCase(TRUE_STRING) + || completeStatus.equalsIgnoreCase(FALSE_STRING)) { return true; } ui.showToUser(ErrorMessages.INVALID_ORDER_STATUS + orderLine); @@ -300,7 +332,7 @@ private static boolean isCompleteStatusAccurate(String orderLine, String complet } private static boolean isValidPrice(String orderLine, Float decodedDishPrice) { - if (decodedDishPrice >= 0) { + if (decodedDishPrice >= MIN_DISH_PRICE) { return true; } ui.showToUser(ErrorMessages.INVALID_DISH_PRICE + orderLine); diff --git a/src/main/java/seedu/cafectrl/storage/Encoder.java b/src/main/java/seedu/cafectrl/storage/Encoder.java index 17dc694d32..f6d7b76a20 100644 --- a/src/main/java/seedu/cafectrl/storage/Encoder.java +++ b/src/main/java/seedu/cafectrl/storage/Encoder.java @@ -23,6 +23,10 @@ public class Encoder { private static final String DIVIDER = " | "; private static final String INGREDIENT_DIVIDER = " - "; private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final String LINE_BREAK = "\n"; + private static final String EMPTY_STRING = ""; + private static final String CARRIAGE_RETURN = "\r"; + private static final String TWO_DECIMAL_PLACE_FORMAT = "%.2f"; //@@author Cazh1 /** @@ -35,7 +39,9 @@ private static ArrayList hashEncoding(ArrayList stringArrayList) String stringArrayListAsString = String.join(", ", stringArrayList).trim(); //The generated String has line breaks, this removes line breaks - String stringArrayListAsStringInOneLine = stringArrayListAsString.replace("\n", "").replace("\r", ""); + String stringArrayListAsStringInOneLine = stringArrayListAsString + .replace(LINE_BREAK, EMPTY_STRING) + .replace(CARRIAGE_RETURN, EMPTY_STRING); //Generate Hash from content int stringArrayListHash = stringArrayListAsStringInOneLine.hashCode(); @@ -138,15 +144,19 @@ public static ArrayList encodeSales(Sales sales) { StringBuilder orderString = new StringBuilder(); //day of each orderList is index + 1 + float orderedDishPrice = order.getOrderedDish().getPrice(); + String orderedDishPriceString = String.format(TWO_DECIMAL_PLACE_FORMAT, orderedDishPrice); + orderString.append((day + 1) + DIVIDER); orderString.append(order.getDishName() + DIVIDER); orderString.append(order.getQuantity() + DIVIDER); - orderString.append(String.format("%.2f", order.getOrderedDish().getPrice()) + DIVIDER); + orderString.append(orderedDishPriceString + DIVIDER); orderString.append(order.getIsComplete()); orderString.append(System.lineSeparator()); encodedList.add(String.valueOf(orderString)); logger.info("Encoded order: " + orderString); } + if (day == sales.getDaysAccounted()) { encodedList = encodeLastSalesDay(encodedList, orderList, day); } diff --git a/src/main/java/seedu/cafectrl/storage/FileManager.java b/src/main/java/seedu/cafectrl/storage/FileManager.java index 7e5f271f33..9803ee9444 100644 --- a/src/main/java/seedu/cafectrl/storage/FileManager.java +++ b/src/main/java/seedu/cafectrl/storage/FileManager.java @@ -20,6 +20,7 @@ */ public class FileManager { + public static final String USER_BASE_DIRECTORY = "user.dir"; private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Ui ui; @@ -35,7 +36,7 @@ public FileManager(Ui ui) { */ public ArrayList readTextFile(String filePath) throws FileNotFoundException { logger.info("Reading text file..."); - String userWorkingDirectory = System.getProperty("user.dir"); + String userWorkingDirectory = System.getProperty(USER_BASE_DIRECTORY); Path dataFilePath = Paths.get(userWorkingDirectory, filePath); File textFile = new File(String.valueOf(dataFilePath)); ArrayList textLines = new ArrayList<>(); @@ -62,7 +63,7 @@ public void checkFileExists(String filePath) throws Exception { throw new Exception(ErrorMessages.MISSING_FILEPATH); } - String userWorkingDirectory = System.getProperty("user.dir"); + String userWorkingDirectory = System.getProperty(USER_BASE_DIRECTORY); Path dataFilePath = Paths.get(userWorkingDirectory, filePath); Path dataFolderPath = dataFilePath.getParent(); File textFile = new File(String.valueOf(dataFilePath)); diff --git a/src/main/java/seedu/cafectrl/storage/Storage.java b/src/main/java/seedu/cafectrl/storage/Storage.java index 28a82dd0fa..6124dcd84b 100644 --- a/src/main/java/seedu/cafectrl/storage/Storage.java +++ b/src/main/java/seedu/cafectrl/storage/Storage.java @@ -19,6 +19,11 @@ * Handles loading and saving data for menu, orderList, pantryStock */ public class Storage { + private static final int INDEX_OFFSET_VALUE = 1; + private static final String HASH_REGEX_1 = "^[0-9]+$"; + private static final String HASH_REGEX_2 = "^-[0-9]+$"; + private static final String HASH_REGEX_3 = "^0{2,}$"; + private static final String ENCODE_DELIMITER = ", "; private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected FileManager fileManager; @@ -30,7 +35,6 @@ public class Storage { private boolean isHashStringTampered = false; private boolean isTamperedMessagePrinted = false; - public Storage (Ui ui) { this.fileManager = new FileManager(ui); this.ui = ui; @@ -49,12 +53,12 @@ private boolean isFileEmpty(ArrayList encodedStringArrayList) { */ private boolean isFileCorrupted(ArrayList encodedStringArrayList) { //Hash string is stored as last in the ArrayList - int lastIndex = encodedStringArrayList.size() - 1; + int lastIndex = encodedStringArrayList.size() - INDEX_OFFSET_VALUE; String hashString = encodedStringArrayList.get(lastIndex); //Checks if the saved Hash is abnormal - if (((!hashString.matches("^[0-9]+$")) && (!hashString.matches("^-[0-9]+$"))) || - hashString.matches("^0{2,}$")) { + if (((!hashString.matches(HASH_REGEX_1)) && (!hashString.matches(HASH_REGEX_2))) || + hashString.matches(HASH_REGEX_3)) { return true; } @@ -64,7 +68,7 @@ private boolean isFileCorrupted(ArrayList encodedStringArrayList) { encodedStringArrayList.remove(lastIndex); //Prepares String in same format as when encoding, generates Hash from the save file content - String encodedMenuAsString = String.join(", ", encodedStringArrayList).trim(); + String encodedMenuAsString = String.join(ENCODE_DELIMITER, encodedStringArrayList).trim(); int encodedMenuHash = encodedMenuAsString.hashCode(); //Checks if the generated Hash matches the saved Hash @@ -92,7 +96,7 @@ public void detectTamper() { isTamperedMessagePrinted = true; } if (isHashStringTampered) { - ui.showToUser(Messages.HASH_STRING_TAMPERED, Messages.HASH_STRING_MESSAGE, ""); + ui.showToUser(Messages.HASH_STRING_TAMPERED, Messages.HASH_STRING_MESSAGE); isHashStringTampered = false; } if (isMenuTampered) { diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index d8de7dfac2..fc51a24c35 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -1,7 +1,6 @@ package seedu.cafectrl.ui; import seedu.cafectrl.command.EditPriceCommand; -import seedu.cafectrl.command.HelpCommand; import seedu.cafectrl.command.ListTotalSalesCommand; public class ErrorMessages { @@ -39,10 +38,8 @@ public class ErrorMessages { public static final String WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE = "Something is wrong with " + "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. \n" + 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.00 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"; @@ -73,7 +70,7 @@ public class ErrorMessages { + "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(>0) " + 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."; @@ -96,18 +93,21 @@ public class ErrorMessages { + "for the add command input"; public static final String NULL_STRING_IN_REPEAT_ARGUMENT = "Null string detected in isRepeatedArgument function"; 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: 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 INVALID_ORDER_QTY = "orders.txt: Invalid quantity (order quantity has to be more than 0)" + ", this order will be removed -> "; public static final String INVALID_DISH_PRICE = "orders.txt: Invalid dish price, this order will be removed -> "; - public static final String WRONG_HELP_FORMAT = "Invalid help command format!\n" - + HelpCommand.MESSAGE_USAGE; public static final String WRONG_LIST_TOTAL_SALES_FORMAT = "Invalid list_total_sales command format!\n" + ListTotalSalesCommand.MESSAGE_USAGE; public static final String MISSING_FILEPATH = "Error in FileManager: No File Path entered"; public static final String MISSING_INGREDIENT_MENU_DATA = "menu.txt: Missing ingredients, " + "this dish will be removed -> "; public static final String DISH_INDEX_NOT_INT = "Sorry! Dish index has to be an int!"; + public static final String EXCEED_MAX_ORDER_QTY = "Order quantity too high! " + + "(order quantity has to be between 1 - 10000)"; + public static final String BELOW_MIN_ORDER_QTY = "Order quantity cannot be less than 1! " + + "(order quantity has to be between 1 - 10000)"; + public static final String MISSING_ORDER_QTY = "Seems like you forgot to add the order quantity"; + public static final String INVALID_INT_ORDER_QTY = "Order quantity is invalid! " + + "(order quantity has to be between 1 - 10000)"; } diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java index d1b83c08fa..b0f3152bd4 100644 --- a/src/main/java/seedu/cafectrl/ui/Messages.java +++ b/src/main/java/seedu/cafectrl/ui/Messages.java @@ -4,6 +4,8 @@ public class Messages { /** Greeting messages */ public static final String LINE_STRING = "------------------------------------------------------------------------"; + public static final String EQUAL_LINE_STRING = "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " + + "= = = ="; public static final String GOODBYE_MESSAGE = "Goodbye <3 Have a great day ahead!"; @@ -65,7 +67,6 @@ public class Messages { public static final String NEXT_DAY_COMMAND_MESSAGE = "Prepare for liftoff! " + "We're about to fast-forward to the next day. " + "Hold onto your hats; here we go!"; - public static final String INITIALISE_STORAGE_MESSAGE = "...Downloading data..."; /** Messages for restocking ingredients */ public static final String AVAILABLE_DISHES = "Listed below are the availability of the dishes for the next order!"; @@ -83,10 +84,6 @@ public class Messages { public static final String INGREDIENTS_CORNER = "+----------------------------------------+--------------+"; public static final String INGREDIENTS_TITLE = "| Ingredient + Quantity |"; /** Messages for decoder **/ - public static final String INVALID_DISH = " does not exist in our menu. \n" - + "You might have tempered with the file and added in a non existing dish.\n" - + "Don't worry :D , we will continue operations without "; - public static final String SAVE_FILE_TAMPER_DETECTED = "Well, well, well, " + "looks like someone's been playing with the save files!\n" + "Let's keep it classy and use the prescribed format below.\n"; @@ -97,18 +94,15 @@ public class Messages { + "{Order Day} | {Dish Name} | {Dish Order Qty} | {Dish Price} | {Order Complete Status}"; public static final String SAVE_FILE_FORMAT_PANTRY_STOCK = "Format for Pantry_stock.txt: \n" + "{Ingredient Name} | {Ingredient Qty} | {Ingredient Unit}"; - public static final String SALES_LAST_DAY_TEXT_TAMPERED = "Unfortunately, any empty order lists after " - + "the latest valid order have been wiped from my memory banks." - + " Poof!" ; - - public static final String SALES_ORDER_TEXT_TAMPERED = "Unfortunately, any orders not following the format " - + "and invalid have been wiped from my memory banks. Poof!" ; public static final String HASH_STRING_TAMPERED = "Alert! It appears the hash string " + "got a makeover without permission."; - public static final String HASH_STRING_MESSAGE = "Please resist the temptation to play Picasso with this string."; + public static final String HASH_STRING_MESSAGE = "Please resist the temptation to play Picasso with this string.\n"; public static final String DONE_LOADING_MENU = "Done loading menu.txt!"; public static final String DONE_LOADING_PANTRY_STOCK = "Done loading pantry_stock.txt!"; public static final String DONE_LOADING_SALES = "Done loading orders.txt!"; + + /** Messages for buy ingredients command */ + public static final String BUY_INGREDIENT_HEADER = "Added to stock:"; } diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java index d5000b7674..e6145de608 100644 --- a/src/main/java/seedu/cafectrl/ui/Ui.java +++ b/src/main/java/seedu/cafectrl/ui/Ui.java @@ -22,6 +22,10 @@ public class Ui { public static final int OFFSET_LIST_INDEX = 1; + public static final String DECIMAL_POINT_STRING = ". "; + public static final String DOLLAR_SIGH_STRING = " $"; + public static final String DISH_LEFT_ALIGN_FORMAT = "|%-55s|"; + public static final String USER_INPUT_CHARACTER = "> "; private final Scanner scanner; /** @@ -36,7 +40,7 @@ public void printLine() { } public String receiveUserInput() { - System.out.print("> "); + System.out.print(USER_INPUT_CHARACTER); return scanner.nextLine(); } @@ -62,7 +66,7 @@ public void showListIngredientsMessage(Dish dish) { } public void showDishNameHeader(Dish dish) { - String dishNameString = String.format("|%-55s|", " Dish: " + dish.getName()); + String dishNameString = String.format(DISH_LEFT_ALIGN_FORMAT, " Dish: " + dish.getName()); showToUser(Messages.INGREDIENTS_END_CAP, dishNameString, Messages.INGREDIENTS_CORNER); @@ -92,7 +96,7 @@ public void printAddDishMessage(Dish dish) { } public void showDishPrice(Dish dish) { - String dishPriceString = String.format("|%-55s|", " Price: $" + dish.getPriceString()); + String dishPriceString = String.format(DISH_LEFT_ALIGN_FORMAT, " Price: $" + dish.getPriceString()); showToUser(dishPriceString, Messages.INGREDIENTS_CORNER); } @@ -107,7 +111,7 @@ public void printDeleteMessage(Dish selectedDish) { } public void printBuyIngredientHeader() { - showToUser("Added to stock:"); + showToUser(Messages.BUY_INGREDIENT_HEADER); } /** @@ -123,8 +127,8 @@ public void showToUser(String... message) { /** * Shows menu to user is table format * - * @param dishName - * @param dishPrice + * @param dishName name text of the dish + * @param dishPrice price text of the dish */ public void formatListMenu(String dishName, String dishPrice) { String leftAlignFormat = "| %-38s | %-12s |%n"; @@ -218,7 +222,7 @@ public void showEmptyMenu() { * @param dishPrice The price of the dish in the menu */ public void showMenuDish(String indexNum, String dishName, String dishPrice) { - formatListMenu(indexNum + ". " + dishName," $" + dishPrice); + formatListMenu(indexNum + DECIMAL_POINT_STRING + dishName, DOLLAR_SIGH_STRING + dishPrice); } public void showIngredientTop() { @@ -280,8 +284,8 @@ public void showIncompleteOrder() { } public void showDishAvailabilityMessage() { - showToUser(Messages.AVAILABLE_DISHES); - showToUser(Messages.LINE_STRING); + showToUser(Messages.AVAILABLE_DISHES, + Messages.EQUAL_LINE_STRING); } public void showPreviousDay() { showToUser(Messages.PREVIOUS_DAY_COMMAND_MESSAGE); diff --git a/src/test/java/seedu/cafectrl/command/AddOrderCommandTest.java b/src/test/java/seedu/cafectrl/command/AddOrderCommandTest.java index 357bbd5c52..e7d2148f42 100644 --- a/src/test/java/seedu/cafectrl/command/AddOrderCommandTest.java +++ b/src/test/java/seedu/cafectrl/command/AddOrderCommandTest.java @@ -28,8 +28,8 @@ public void execute_addValidOrder_expectOneOrder() { ingredients2.add(new Ingredient("rice", 50, "g")); ArrayList menuItems = new ArrayList<>(); - Dish dishChickenRice = new Dish("Chicken Rice", ingredients, 2.50F); - Dish dishChickenCurry = new Dish("Chicken Curry", ingredients2, 4.30F); + Dish dishChickenRice = new Dish("chicken rice", ingredients, 2.50F); + Dish dishChickenCurry = new Dish("chicken curry", ingredients2, 4.30F); menuItems.add(dishChickenRice); menuItems.add(dishChickenCurry); Menu menu = new Menu(menuItems); @@ -63,7 +63,7 @@ public void execute_addValidOrder_expectOneOrder() { + "Total order cost: $5.00" + Messages.LINE_STRING + Messages.AVAILABLE_DISHES - + Messages.LINE_STRING + + Messages.EQUAL_LINE_STRING + "Dish: chicken rice" + "Available quantity: 8" + Messages.LINE_STRING diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java index bdf4e2cdb0..15b8f349bb 100644 --- a/src/test/java/seedu/cafectrl/parser/ParserTest.java +++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java @@ -369,9 +369,9 @@ void parseCommand_dishWithOneIngredientForAddDish_dishAddedToMenu() { //Test for correct parsing of dish arguments Dish getOutputDish = menu.getDishFromId(0); - assertEquals("Christmas Ham", getOutputDish.getName()); + assertEquals("christmas ham", getOutputDish.getName()); assertEquals((float) 50.0, getOutputDish.getPrice()); - assertEquals("[Ham - 1000g]", getOutputDish.getIngredients().toString()); + assertEquals("[ham - 1000g]", getOutputDish.getIngredients().toString()); } @Test @@ -394,7 +394,7 @@ void parseCommand_dishWithThreeIngredientsForAddDish_dishContainsThreeIngredient //Test for correct parsing of dish arguments Dish getOutputDish = menu.getDishFromId(0); - assertEquals("Chicken Rice", getOutputDish.getName()); + assertEquals("chicken rice", getOutputDish.getName()); assertEquals((float) 2.0, getOutputDish.getPrice()); assertEquals("[rice - 100g, chicken - 200g, water - 100ml]", getOutputDish.getIngredients().toString()); } @@ -608,9 +608,9 @@ void parseCommand_whitespaceBetweenArgumentsForAddDish_dishAddedToMenu() { //Test for correct parsing of dish arguments Dish getOutputDish = menu.getDishFromId(0); - assertEquals("Christmas Ham", getOutputDish.getName()); + assertEquals("christmas ham", getOutputDish.getName()); assertEquals((float) 50.0, getOutputDish.getPrice()); - assertEquals("[Ham - 1000g]", getOutputDish.getIngredients().toString()); + assertEquals("[ham - 1000g]", getOutputDish.getIngredients().toString()); } @Test