diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 84346d5aba..ef64a6a50e 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -2,7 +2,7 @@ Display | Name | Github Profile | Portfolio --------|:--------:|:----------------------------------------:|:---------: -![](../images/aboutUs/shanice.jpg) | Shanice | [Github](https://github.com/ShaniceTang) | [Portfolio](team/shanicetang.md) +![](images/aboutUs/shanice.jpg) | Shanice | [Github](https://github.com/ShaniceTang) | [Portfolio](team/shanicetang.md) ![](https://via.placeholder.com/100.png?text=Photo) | Naychi | [Github](https://github.com/NaychiMin/tp) | [Portfolio](team/NaychiMin.md) ![](https://via.placeholder.com/100.png?text=Photo) | Zi Yi | [Github](https://github.com/ziyi105) | [Portfolio](team/ziyi105.md) ![](https://via.placeholder.com/100.png?text=Photo) | Dexter Hoon | [Github](https://github.com/DextheChik3n) | [Portfolio](team/dexthechik3n.md) diff --git a/docs/images/aboutUs/shanice.jpg b/docs/images/aboutUs/shanice.jpg new file mode 100644 index 0000000000..051f897437 Binary files /dev/null and b/docs/images/aboutUs/shanice.jpg differ diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 3b9114b03a..492fd6a06e 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.logging.Level; import java.util.logging.Logger; @@ -27,6 +28,7 @@ public class Decoder { 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()); //@@author ShaniceTang @@ -41,14 +43,23 @@ public static Menu decodeMenuData(ArrayList textLines) { ArrayList menuDishList = new ArrayList<>(); for(String dishString : textLines) { logger.info("Line to decode: " + dishString); + decodeDishString(dishString, menuDishList); + } + return new Menu(menuDishList); + } + + private static void decodeDishString(String dishString, ArrayList menuDishList) { + try { String[] dishStringArray = dishString.split(DIVIDER); String dishName = dishStringArray[0].trim(); float dishPrice = Float.parseFloat(dishStringArray[1]); String[] ingredientStringArray = Arrays.copyOfRange(dishStringArray, 2, dishStringArray.length); ArrayList ingredientsList = decodeIngredientData(ingredientStringArray); menuDishList.add(new Dish(dishName, ingredientsList, dishPrice)); + } catch (Exception e) { + logger.log(Level.WARNING, "Line corrupted: " + e.getMessage(), e); + ui.showToUser(ErrorMessages.INVALID_MENU_DATA + dishString); } - return new Menu(menuDishList); } /** @@ -57,19 +68,26 @@ public static Menu decodeMenuData(ArrayList textLines) { * @param ingredientsStringArray An array of strings containing encoded ingredient data. * @return An ArrayList of Ingredient objects containing the decoded ingredient information. */ - private static ArrayList decodeIngredientData(String[] ingredientsStringArray) { + private static ArrayList decodeIngredientData(String[] ingredientsStringArray) throws Exception { ArrayList ingredientList = new ArrayList<>(); for(String ingredientString : ingredientsStringArray) { logger.info("Ingredient to decode: " + ingredientString); - String[] array = ingredientString.split(" "); + String[] array = ingredientString.split(INGREDIENT_DIVIDER); String name = array[0].trim(); - int qty = Integer.parseInt(array[1]); + int qty = Integer.parseInt(array[1].trim()); String unit = array[2].trim(); + checkUnitValidity(unit); ingredientList.add(new Ingredient(name, qty, unit)); } return ingredientList; } + private static void checkUnitValidity(String unit) throws Exception { + if (!Parser.isValidUnit(unit) || Parser.isEmptyUnit(unit)) { + throw new Exception(); + } + } + //@@author ziyi105 /** * Decodes raw string from pantry stock data file and create ingredient object from the data diff --git a/src/main/java/seedu/cafectrl/storage/Encoder.java b/src/main/java/seedu/cafectrl/storage/Encoder.java index f7e94ff3db..9bbffa0dc5 100644 --- a/src/main/java/seedu/cafectrl/storage/Encoder.java +++ b/src/main/java/seedu/cafectrl/storage/Encoder.java @@ -21,6 +21,7 @@ public class Encoder { public static final String NULL_ORDER_DAY = "the last day has no orders but please account for it"; private static final String DIVIDER = " | "; + private static final String INGREDIENT_DIVIDER = " - "; private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); //@@author ShaniceTang /** @@ -36,7 +37,7 @@ public static ArrayList encodeMenu(Menu menu) { for(Dish dish : menuDishList) { StringBuilder dishString = new StringBuilder(); dishString.append(dish.getName() + DIVIDER); - dishString.append(dish.getPrice() + DIVIDER); + dishString.append(dish.getPrice()); dishString.append(encodeIngredientList(dish.getIngredients())); dishString.append(System.lineSeparator()); menuStringList.add(String.valueOf(dishString)); @@ -54,9 +55,10 @@ public static ArrayList encodeMenu(Menu menu) { private static StringBuilder encodeIngredientList(ArrayList ingredientList) { StringBuilder ingredientListString = new StringBuilder(); for(Ingredient ingredient : ingredientList) { - ingredientListString.append(ingredient.getName() + " "); - ingredientListString.append(ingredient.getQty() + " "); - ingredientListString.append(ingredient.getUnit() + DIVIDER); + ingredientListString.append(DIVIDER); + ingredientListString.append(ingredient.getName() + INGREDIENT_DIVIDER); + ingredientListString.append(ingredient.getQty() + INGREDIENT_DIVIDER); + ingredientListString.append(ingredient.getUnit()); } return ingredientListString; } diff --git a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java index d6f670a832..9d6a5dd672 100644 --- a/src/main/java/seedu/cafectrl/ui/ErrorMessages.java +++ b/src/main/java/seedu/cafectrl/ui/ErrorMessages.java @@ -74,6 +74,7 @@ public class ErrorMessages { + "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?"; + public static final String INVALID_MENU_DATA = "menu.txt: Invalid format, this dish will be removed -> "; 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"