diff --git a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java index 1cf66e26e8..546947b9a6 100644 --- a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java +++ b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java @@ -13,7 +13,7 @@ public class EditPriceCommand extends Command { public static final String COMMAND_WORD = "edit_price"; public static final String MESSAGE_USAGE = "To edit price of a menu item: \n" + "edit_price dish/DISH_INDEX price/NEW_PRICE\n" - + "Example: edit_price index/1 price/4.50"; + + "Example: edit_price dish/1 price/4.50"; protected Menu menu; protected Ui ui; diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index 425ea6f047..1cbd061ce7 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -67,7 +67,7 @@ public class Parser implements ParserUtil { /** The rest of Command Handler Patterns*/ private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)"; private static final String DELETE_ARGUMENT_STRING = "(\\d+)"; - private static final String EDIT_PRICE_ARGUMENT_STRING = "dish/(.*) price/(.*)"; + 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]+" + "(?:, ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+)*)"; private static final String SHOW_SALE_BY_DAY_ARGUMENT_STRING = "day/(\\d+)"; @@ -179,7 +179,13 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u float newPrice; try { - String dishIndexText = matcher.group(dishIndexGroup).replaceAll("\\s", ""); + String dishIndexText = matcher.group(dishIndexGroup).trim(); + + // Check whether the index is empty + if (dishIndexText.equals("")) { + return new IncorrectCommand(ErrorMessages.MISSING_DISH_IN_EDIT_PRICE, ui); + } + dishIndex = Integer.parseInt(dishIndexText); // Check whether the dish index is valid @@ -304,8 +310,12 @@ static float parsePriceToFloat(String priceText) throws ParserException { final Pattern priceTwoDecimalPlacePattern = Pattern.compile("^-?[0-9]\\d*(\\.\\d{0,2})?$"); Matcher priceMatcher = priceTwoDecimalPlacePattern.matcher(trimmedPriceText); + // Check whether price text is empty + if (priceText.equals("")) { + throw new ParserException(ErrorMessages.MISSING_PRICE); + } if (!priceMatcher.matches()) { - throw new ParserException(ErrorMessages.PRICE_TOO_MANY_DECIMAL_PLACES); + throw new ParserException(ErrorMessages.WRONG_PRICE_TYPE_FOR_EDIT_PRICE); } float price; diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index b15e573d0e..ed97947d71 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -24,13 +24,13 @@ public class ErrorMessages { + "for delete command."; public static final String MISSING_ARGUMENT_FOR_BUY_INGREDIENT = "Error: Missing arguments " + "for buy ingredient command."; - public static final String WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE = "Error: " - + "Invalid argument type. \n " - + "Make sure dish index is of type int"; + 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!"; public static final String WRONG_PRICE_TYPE_FOR_EDIT_PRICE = "Error: " + "Invalid price! \n " - + "Price can only have 2 decimal place and it must be " - + "within the range of 0.00 to 1000000!"; + + "Price must be a float and within the range of " + + "0.00 to 1000000 with up to 2 decimal place"; 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? " @@ -59,4 +59,8 @@ 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 MISSING_PRICE = "Did you forget to include price? Just a reminder: " + + "price can only have up to 2 decimal place!"; + public static final String MISSING_DISH_IN_EDIT_PRICE = "Sorry, I didnt catch the dish index, " + + "did you forget to include it in your command?"; } diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java index 54dd844b23..07778accac 100644 --- a/src/test/java/seedu/cafectrl/parser/ParserTest.java +++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java @@ -259,7 +259,7 @@ public void showToUser(String... message) { ParserUtil parserUtil = new Parser(); Command commandReturned = parserUtil.parseCommand(menu, testUserInput, ui, pantry, sales, currentDate); commandReturned.execute(); - assertEquals(ErrorMessages.WRONG_DISH_INDEX_TYPE_FOR_EDIT_PRICE, actualOutput.get(0)); + assertEquals(ErrorMessages.MISSING_DISH_IN_EDIT_PRICE, actualOutput.get(0)); } @Test