From 124baf261f741b042eeb2a7fb8a0f246c07da2b5 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 13:25:04 +0800 Subject: [PATCH 01/14] Update coding standard in CafeCtrl.java --- src/main/java/seedu/cafectrl/CafeCtrl.java | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java index bd18c8ebbe..da399ecd72 100644 --- a/src/main/java/seedu/cafectrl/CafeCtrl.java +++ b/src/main/java/seedu/cafectrl/CafeCtrl.java @@ -23,26 +23,25 @@ */ public class CafeCtrl { - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Ui ui; - private Menu menu; + private final Storage storage; + private final Pantry pantry; + private final Menu menu; + private final Sales sales; + private final CurrentDate currentDate; + private Command command; - private Pantry pantry; - private Sales sales; - private CurrentDate currentDate; - private Storage storage; /** * Private constructor for the CafeCtrl class, used for initializing the user interface and menu list. */ - private CafeCtrl() { initLogger(); this.ui = new Ui(); this.storage = new Storage(this.ui); - this.sales = new Sales(); - this.menu = this.storage.loadMenu(); this.pantry = this.storage.loadPantryStock(); + this.menu = this.storage.loadMenu(); this.sales = this.storage.loadOrderList(menu); this.currentDate = new CurrentDate(sales); @@ -59,6 +58,7 @@ private CafeCtrl() { private void run() { ui.showWelcome(); ui.printLine(); + do { try { String fullUserInput = ui.receiveUserInput(); @@ -82,8 +82,9 @@ private void initLogger() { logger.setUseParentHandlers(false); try { FileHandler fileHandler = new FileHandler("cafeCtrl.log"); - logger.addHandler(fileHandler); SimpleFormatter formatter = new SimpleFormatter(); + + logger.addHandler(fileHandler); fileHandler.setFormatter(formatter); } catch (IOException e) { e.printStackTrace(); @@ -94,6 +95,4 @@ public static void main(String[] args) { CafeCtrl cafeCtrl = new CafeCtrl(); cafeCtrl.run(); } - } - From 6396a8089cfb378141e6f1b72a5acf7b183a82d6 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 13:27:11 +0800 Subject: [PATCH 02/14] Update coding standard in EditPriceCommand and HelpCommand --- src/main/java/seedu/cafectrl/command/EditPriceCommand.java | 6 +++--- src/main/java/seedu/cafectrl/command/HelpCommand.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java index 6f72ac318a..7ef5f0a436 100644 --- a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java +++ b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java @@ -18,11 +18,11 @@ public class EditPriceCommand extends Command { + "edit_price dish/DISH_INDEX price/NEW_PRICE\n" + "Example: edit_price dish/1 price/4.50"; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); - protected Menu menu; - protected Ui ui; + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final int menuID; private final float newPrice; + protected Menu menu; + protected Ui ui; public EditPriceCommand(int menuID, float newPrice, Menu menu, Ui ui) { this.menuID = menuID; diff --git a/src/main/java/seedu/cafectrl/command/HelpCommand.java b/src/main/java/seedu/cafectrl/command/HelpCommand.java index 80e92e6902..e2cfc3f4b5 100644 --- a/src/main/java/seedu/cafectrl/command/HelpCommand.java +++ b/src/main/java/seedu/cafectrl/command/HelpCommand.java @@ -8,10 +8,9 @@ //@@author ziyi105 public class HelpCommand extends Command { public static final String COMMAND_WORD = "help"; - public static final String MESSAGE_USAGE = "To view all commands:\n" - + COMMAND_WORD; + public static final String MESSAGE_USAGE = "To view all commands:\n" + COMMAND_WORD; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Ui ui; @@ -22,6 +21,7 @@ public HelpCommand(Ui ui) { @Override public void execute() { logger.info("Executing HelpCommand..."); + ui.printLine(); ui.showHelp(); } From d1abc919090ef90b39323b1888e5d7a3dac39f43 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 14:19:16 +0800 Subject: [PATCH 03/14] Update coding standard up to Pantry.java --- src/main/java/seedu/cafectrl/data/Chef.java | 9 ++--- .../java/seedu/cafectrl/data/CurrentDate.java | 19 ++++++---- src/main/java/seedu/cafectrl/data/Menu.java | 38 ++++++++++++------- src/main/java/seedu/cafectrl/data/Order.java | 7 ++-- .../java/seedu/cafectrl/data/OrderList.java | 5 ++- src/main/java/seedu/cafectrl/data/Pantry.java | 18 ++++++--- .../java/seedu/cafectrl/data/dish/Dish.java | 10 +++-- .../seedu/cafectrl/data/dish/Ingredient.java | 18 ++++++--- 8 files changed, 80 insertions(+), 44 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/Chef.java b/src/main/java/seedu/cafectrl/data/Chef.java index 1a3c6f6393..d6799ee974 100644 --- a/src/main/java/seedu/cafectrl/data/Chef.java +++ b/src/main/java/seedu/cafectrl/data/Chef.java @@ -9,13 +9,10 @@ public class Chef { - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Order order; private final Pantry pantry; private final Ui ui; - private Menu menu; - private final DecimalFormat dollarValue = new DecimalFormat("0.00"); - public Chef(Order order, Pantry pantry, Ui ui) { this.order = order; @@ -28,9 +25,11 @@ public void cookDish() { try { if (!order.getIsComplete()) { ui.showChefMessage(); + boolean isComplete = pantry.isDishCooked(order.getIngredientList()); - logger.info("Dish cooked: " + isComplete); order.setComplete(isComplete); + + logger.info("Dish cooked: " + isComplete); } } catch (Exception e) { logger.log(Level.WARNING, "Unsuccessful order: " + e.getMessage(), e); diff --git a/src/main/java/seedu/cafectrl/data/CurrentDate.java b/src/main/java/seedu/cafectrl/data/CurrentDate.java index 654f4db0b4..42f4dd06ab 100644 --- a/src/main/java/seedu/cafectrl/data/CurrentDate.java +++ b/src/main/java/seedu/cafectrl/data/CurrentDate.java @@ -3,24 +3,26 @@ import java.util.ArrayList; public class CurrentDate { + private final static int ZERO = 0; + private final static int ONE = 1; private int currentDay; public CurrentDate() { - currentDay = 0; + currentDay = ZERO; } public CurrentDate(int day) { - currentDay = day - 1; + currentDay = day - ONE; } public CurrentDate(Sales sales) { setDate(sales); } public void nextDay() { - currentDay += 1; + currentDay += ONE; } public void previousDay() { - currentDay -= 1; + currentDay -= ONE; } public int getCurrentDay() { @@ -30,15 +32,16 @@ public int getCurrentDay() { /** * Sets the current date to the latest date the user left off * - * @param sales Used to access the number of orderlist created + * @param sales Used to access the number of order list created */ public void setDate(Sales sales) { ArrayList orderLists = sales.getOrderLists(); int orderListsSize = orderLists.size(); - if (orderListsSize > 0) { - currentDay = orderListsSize - 1; + + if (orderListsSize > ZERO) { + currentDay = orderListsSize - ONE; } else { - currentDay = 0; + currentDay = ZERO; } } } diff --git a/src/main/java/seedu/cafectrl/data/Menu.java b/src/main/java/seedu/cafectrl/data/Menu.java index 3fd6d9e9cf..fe6eab615d 100644 --- a/src/main/java/seedu/cafectrl/data/Menu.java +++ b/src/main/java/seedu/cafectrl/data/Menu.java @@ -8,7 +8,7 @@ import java.util.logging.Logger; public class Menu { - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private ArrayList menuItems; public Menu() { @@ -22,9 +22,11 @@ public Menu(ArrayList menuItems) { public ArrayList getMenuItemsList() { return menuItems; } + public int getSize() { return menuItems.size(); } + public Dish getDishFromId(int menuID) { return menuItems.get(menuID); } @@ -40,24 +42,13 @@ public Dish getDishFromName(String dishName) { for (int i = 0; i < getSize(); i++) { String menuDishName = getDishFromId(i).getName(); String formattedMenuDishName = menuDishName.toLowerCase().trim(); + if (formattedMenuDishName.equals(formattedDishName)){ return getDishFromId(i); } } return null; } - public void removeDish(int menuID) { - menuItems.remove(menuID); - } - public void addDish(Dish dish) { - menuItems.add(dish); - } - - public boolean isValidDishIndex(int dishIndex) { - logger.info("Checking if dish index " + dishIndex + " is valid..."); - int offSetDishIndex = dishIndex - Ui.OFFSET_LIST_INDEX; - return offSetDishIndex >= 0 && offSetDishIndex < this.getSize(); - } //@@author NaychiMin /** @@ -76,4 +67,25 @@ public ArrayList getAggregatedOrders() { } return aggregatedOrders; } + + //@@author ziyi105 + /** + * Checks whether the dish index can be found in the menu + * @param dishIndex dish index to be checked + * @return true if it is valid, false otherwise + */ + public boolean isValidDishIndex(int dishIndex) { + logger.info("Checking if dish index " + dishIndex + " is valid..."); + + int offSetDishIndex = dishIndex - Ui.OFFSET_LIST_INDEX; + return offSetDishIndex >= 0 && offSetDishIndex < this.getSize(); + } + + //@@author DextheChik3n + public void removeDish(int menuID) { + menuItems.remove(menuID); + } + public void addDish(Dish dish) { + menuItems.add(dish); + } } diff --git a/src/main/java/seedu/cafectrl/data/Order.java b/src/main/java/seedu/cafectrl/data/Order.java index 6d8250ccfb..3904bd0400 100644 --- a/src/main/java/seedu/cafectrl/data/Order.java +++ b/src/main/java/seedu/cafectrl/data/Order.java @@ -11,19 +11,19 @@ public class Order { private final Dish orderedDish; private int dishQty; private final ArrayList ingredientList; - private boolean isComplete = false; private float totalOrderCost; + private boolean isComplete = false; public Order(Dish orderedDish, int dishQty) { - this.dishQty = dishQty; this.orderedDish = orderedDish; + this.dishQty = dishQty; this.ingredientList = setIngredientList(); this.totalOrderCost = calculateTotalOrderCost(); } public Order(Dish orderedDish, int dishQty, float orderCost, boolean isComplete) { - this.dishQty = dishQty; this.orderedDish = orderedDish; + this.dishQty = dishQty; this.ingredientList = setIngredientList(); this.totalOrderCost = orderCost; this.isComplete = isComplete; @@ -59,6 +59,7 @@ private ArrayList setIngredientList() { String ingredientName = ingredient.getName(); int ingredientQty = ingredient.getQty() * dishQty; String ingredientUnit = ingredient.getUnit(); + dishIngredient.add(new Ingredient(ingredientName, ingredientQty, ingredientUnit)); } return dishIngredient; diff --git a/src/main/java/seedu/cafectrl/data/OrderList.java b/src/main/java/seedu/cafectrl/data/OrderList.java index f38bb3ef81..9f0a1587d0 100644 --- a/src/main/java/seedu/cafectrl/data/OrderList.java +++ b/src/main/java/seedu/cafectrl/data/OrderList.java @@ -14,7 +14,7 @@ public class OrderList { private static final DecimalFormat dollarValue = new DecimalFormat("0.00"); private static final String HEADER_FORMAT = "%-20s %-10s %-20s\n"; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private ArrayList orderList; private float totalOrderListCost; @@ -78,6 +78,7 @@ public void printOrderList(Menu menu, Ui ui) { */ private void aggregateOrder(Order order, ArrayList aggregatedOrders) { logger.info("Aggregating order..."); + if (order.getIsComplete()) { int index = getIndexByDishName(aggregatedOrders, order.getDishName()); aggregatedOrders.get(index) @@ -99,6 +100,7 @@ private int getIndexByDishName(ArrayList aggregatedOrders, String dishNam Order order = aggregatedOrders.get(i); String orderDishName = order.getDishName().trim(); dishName = dishName.trim(); + if (orderDishName.equalsIgnoreCase(dishName)) { return i; } @@ -115,6 +117,7 @@ private int getIndexByDishName(ArrayList aggregatedOrders, String dishNam private float calculateTotalCost(ArrayList orders) { logger.info("Calculating total cost..."); float totalCost = 0; + for (Order order : orders) { totalCost += order.getTotalOrderCost(); logger.info("Total cost: " + totalCost); diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java index 121f68037b..4e52871f07 100644 --- a/src/main/java/seedu/cafectrl/data/Pantry.java +++ b/src/main/java/seedu/cafectrl/data/Pantry.java @@ -12,9 +12,9 @@ public class Pantry { - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private final Ui ui; private ArrayList pantryStock; - private Ui ui; //@@author NaychiMin public Pantry(Ui ui, ArrayList pantryStock) { @@ -71,6 +71,7 @@ public Ingredient addIngredientToStock (String name, int qty, String unit) { */ private Ingredient addIngredientQuantity(int qty, int ingredientIndex, String unit) { Ingredient ingredient = pantryStock.get(ingredientIndex); + if (!unit.equalsIgnoreCase(ingredient.getUnit())) { logger.warning("Unit does not match previous unit"); throw new RuntimeException(ingredient.getName() @@ -81,6 +82,7 @@ private Ingredient addIngredientQuantity(int qty, int ingredientIndex, String un qty += ingredient.getQty(); //adds new qty to current qty ingredient.setQty(qty); logger.info("New quantity: " + qty); + return ingredient; } @@ -93,6 +95,7 @@ private Ingredient addIngredientQuantity(int qty, int ingredientIndex, String un private int getIndexOfIngredient(String name) { for (int i = 0; i < pantryStock.size(); i++) { String ingredientName = pantryStock.get(i).getName().trim(); + if (name.equalsIgnoreCase(ingredientName)) { return i; } @@ -108,6 +111,7 @@ private int getIndexOfIngredient(String name) { */ public boolean isDishCooked(ArrayList dishIngredients) { logger.info("Checking if dish can be cooked"); + //for each ingredient that is used in the dish, update the stock of ingredient left. for (Ingredient dishIngredient : dishIngredients) { Ingredient usedIngredientFromStock = getIngredient(dishIngredient); @@ -119,6 +123,7 @@ public boolean isDishCooked(ArrayList dishIngredients) { int stockQuantity = usedIngredientFromStock.getQty(); int usedQuantity = dishIngredient.getQty(); int finalQuantity = stockQuantity - usedQuantity; + if (finalQuantity < 0) { return false; } @@ -148,11 +153,13 @@ private Ingredient getIngredient(Ingredient dishIngredient) { public void calculateDishAvailability(Menu menu, Order order) { logger.info("Calculating dish availability..."); int menuSize = menu.getSize(); + for (int i = 0; i < menuSize; i++) { Dish dish = menu.getDishFromId(i); ui.showToUser("Dish: " + dish.getName()); int numberOfDishes = calculateMaxDishes(dish, menu, order); ui.showDishAvailability(numberOfDishes); + if (i != menuSize - 1) { ui.printLine(); } @@ -167,8 +174,9 @@ public void calculateDishAvailability(Menu menu, Order order) { public int calculateMaxDishes(Dish dish, Menu menu, Order order) { logger.info("Calculating max number of dishes possible..."); int maxNumofDish = Integer.MAX_VALUE; - ArrayList dishIngredients = retrieveIngredientsForDish(dish.getName(), menu); boolean isRestockHeaderDisplayed = false; + ArrayList dishIngredients = retrieveIngredientsForDish(dish.getName(), menu); + for (Ingredient dishIngredient : dishIngredients) { int numOfDish = calculateMaxDishForEachIngredient(dishIngredient); maxNumofDish = Math.min(numOfDish, maxNumofDish); @@ -197,6 +205,7 @@ private boolean showRestockHeaderIfNeeded(boolean isRestockHeaderDisplayed) { private void handleIncompleteDishCase(Ingredient dishIngredient, Order order) { int orderQuantity = order.getQuantity(); + if (calculateMaxDishForEachIngredient(dishIngredient) < orderQuantity) { handleRestock(dishIngredient, orderQuantity); } @@ -216,6 +225,7 @@ private void handleZeroDishCase(Ingredient dishIngredient) { private int calculateMaxDishForEachIngredient(Ingredient dishIngredient) { logger.info("Calculating max dish for each ingredient..."); Ingredient usedIngredientFromStock = getIngredient(dishIngredient); + if (usedIngredientFromStock == null) { return 0; } @@ -259,5 +269,3 @@ public ArrayList retrieveIngredientsForDish(String orderedDish, Menu return dishIngredients; } } - - diff --git a/src/main/java/seedu/cafectrl/data/dish/Dish.java b/src/main/java/seedu/cafectrl/data/dish/Dish.java index cf4c3c01a6..3921eaa5a3 100644 --- a/src/main/java/seedu/cafectrl/data/dish/Dish.java +++ b/src/main/java/seedu/cafectrl/data/dish/Dish.java @@ -4,11 +4,12 @@ import java.text.DecimalFormat; public class Dish { - private String name; - private ArrayList ingredients; - private float price; private final DecimalFormat dollarValue = new DecimalFormat("0.00"); + private final String name; + private final ArrayList ingredients; + private float price; + public Dish(String name, ArrayList ingredients, float price) { this.name = name; this.ingredients = ingredients; @@ -39,12 +40,12 @@ public void setPrice(float newPrice) { this.price = Math.abs(newPrice); } + //@@author ziyi105 @Override public String toString() { return this.name + " $" + this.dollarValue.format(this.price); } - //@@author ziyi105 /** * Compare the original price and new price * @param otherPrice price value to be compared with @@ -53,6 +54,7 @@ public String toString() { public int comparePrice(float otherPrice) { String formattedPrice = this.dollarValue.format(price); String formattedNewPrice = this.dollarValue.format(otherPrice); + return formattedPrice.compareTo(formattedNewPrice); } } diff --git a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java index a25b3b27c4..5226496a86 100644 --- a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java +++ b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java @@ -1,20 +1,20 @@ package seedu.cafectrl.data.dish; public class Ingredient { - private String name; + private final String name; + private final String unit; private int qty; - private String unit; public Ingredient(String name) { this.name = name; - this.qty = 0; this.unit = null; + this.qty = 0; } public Ingredient(String name, int qty, String unit) { this.name = name; - this.qty = qty; this.unit = unit; + this.qty = qty; } public String getName() { @@ -38,8 +38,16 @@ public String toString() { return name + " - " + qty + unit; } + /** + * Compare the name of this ingredient to the other ingredient + * @param obj the other ingredient to be compared with + * @return true if they have the same name, false otherwise + */ @Override public boolean equals(Object obj) { - return this.toString().equals(obj.toString()); + if (obj instanceof Ingredient) { + return this.name.equals(((Ingredient) obj).name); + } + return false; } } From f6dad255670855668b5efe7ef50e453abf94dbd9 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 14:34:40 +0800 Subject: [PATCH 04/14] Update coding standard --- src/main/java/seedu/cafectrl/data/Menu.java | 1 + src/main/java/seedu/cafectrl/data/Sales.java | 9 ++-- .../java/seedu/cafectrl/parser/Parser.java | 44 +++++++++++++------ .../java/seedu/cafectrl/storage/Decoder.java | 5 +-- .../java/seedu/cafectrl/storage/Encoder.java | 8 +++- .../java/seedu/cafectrl/storage/Storage.java | 12 ++--- 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/Menu.java b/src/main/java/seedu/cafectrl/data/Menu.java index fe6eab615d..8cdeb4636a 100644 --- a/src/main/java/seedu/cafectrl/data/Menu.java +++ b/src/main/java/seedu/cafectrl/data/Menu.java @@ -71,6 +71,7 @@ public ArrayList getAggregatedOrders() { //@@author ziyi105 /** * Checks whether the dish index can be found in the menu + * * @param dishIndex dish index to be checked * @return true if it is valid, false otherwise */ diff --git a/src/main/java/seedu/cafectrl/data/Sales.java b/src/main/java/seedu/cafectrl/data/Sales.java index b3cd9316a2..7179b63c95 100644 --- a/src/main/java/seedu/cafectrl/data/Sales.java +++ b/src/main/java/seedu/cafectrl/data/Sales.java @@ -25,13 +25,13 @@ public Sales() { public Sales(ArrayList orderLists) { this.orderLists = orderLists; - this.daysAccounted = orderLists.size() - 1; + this.daysAccounted = orderLists.size() - DAY_DISPLAY_OFFSET; } public Sales(OrderList orderList) { this.orderLists = new ArrayList<>(); orderLists.add(orderList); - this.daysAccounted = orderLists.size() - 1; + this.daysAccounted = orderLists.size() - DAY_DISPLAY_OFFSET; } public void addOrderList(OrderList orderList) { @@ -39,7 +39,7 @@ public void addOrderList(OrderList orderList) { } public void nextDay() { - this.daysAccounted += 1; + this.daysAccounted += DAY_DISPLAY_OFFSET; } public int getDaysAccounted() { @@ -92,7 +92,7 @@ public void printSales(Ui ui, Menu menu) { */ public void printSaleByDay(Ui ui, Menu menu, int day) { logger.info("Printing sales by day..."); - int orderListIndex = day - 1; + int orderListIndex = day - DAY_DISPLAY_OFFSET; try { OrderList orderList = orderLists.get(orderListIndex); if (orderList.isEmpty() || !orderList.hasCompletedOrders()) { @@ -117,5 +117,4 @@ public boolean isOrderListsEmpty() { } return true; } - //@@author } diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index 966ec58574..67ffd72a22 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -161,7 +161,7 @@ public Command parseCommand(Menu menu, String userInput, Ui ui, } } - //All prepareCommand Classes + /** All prepareCommand Classes **/ //@@author Cazh1 /** * Prepares the ListMenuCommand @@ -177,6 +177,7 @@ private static Command prepareListMenu(Menu menu, Ui ui) { //@@author ziyi105 /** * Parse argument in the context of edit price command + * * @param menu menu of the current session * @param arguments string that matches group arguments * @return new EditDishCommand @@ -229,7 +230,9 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u //@@author DextheChik3n /** - * Parses the user input text into ingredients to form a Dish that is added to the Menu + * Parses the user input text into ingredients to form a Dish + * that is added to the Menu + * * @param arguments string that matches group arguments * @param menu Menu of the current session * @param ui Ui of the current session @@ -309,7 +312,8 @@ private static void detectErrorPostDishNameParse(String dishName, Menu menu) thr /** * Parses the user's input text ingredients. * - * @param ingredientsListString user's input string of ingredients, multiple ingredients seperated by ',' is allowed + * @param ingredientsListString user's input string of ingredients, + * multiple ingredients seperated by ',' is allowed * @param menu * @return list of ingredients that consists of the dish * @throws ParserException if the input string does not match the constraints @@ -337,23 +341,27 @@ private static ArrayList parseIngredients( } private static void parseIngredient( - boolean isExcludeRepeatedIngredients, Menu menu, String inputIngredient, ArrayList ingredients) + boolean isExcludeRepeatedIngredients, Menu menu, + String inputIngredient, ArrayList ingredients) throws ParserException { Matcher ingredientMatcher = detectErrorPreIngredientParse(inputIngredient); String ingredientName = ingredientMatcher.group(INGREDIENT_NAME_REGEX_GROUP_LABEL).trim(); + //ingredientQtyString contains the input text after the "qty/" argument String ingredientQtyString = ingredientMatcher.group(INGREDIENT_QTY_REGEX_GROUP_LABEL).trim(); //check the formatting of text after ingredient qty argument (qty/) final Pattern ingredientQtyFormatPattern = Pattern.compile(INGREDIENT_QTY_FORMAT_REGEX); Matcher ingredientQtyMatcher = ingredientQtyFormatPattern.matcher(ingredientQtyString); + if (!ingredientQtyMatcher.matches()) { throw new ParserException(ErrorMessages.INVALID_INGREDIENT_QTY_FORMAT); } String ingredientUnit = ingredientQtyMatcher.group(INGREDIENT_QTY_UNIT_REGEX_GROUP_LABEL); - int ingredientQty = Integer.parseInt(ingredientQtyMatcher.group(INGREDIENT_QTY_VALUE_REGEX_GROUP_LABEL)); + int ingredientQty = Integer.parseInt(ingredientQtyMatcher + .group(INGREDIENT_QTY_VALUE_REGEX_GROUP_LABEL)); detectErrorPostIngredientParse(isExcludeRepeatedIngredients, ingredientName, ingredientQty, ingredientUnit, ingredients); @@ -365,7 +373,8 @@ private static void parseIngredient( ingredients.add(ingredient); } - private static Matcher detectErrorPreIngredientParse(String inputIngredient) throws ParserException { + private static Matcher detectErrorPreIngredientParse(String inputIngredient) + throws ParserException { if (isRepeatedArgument(inputIngredient, INGREDIENT_ARGUMENT)) { logger.log(Level.WARNING, "Repeated ingredient/ argument!"); throw new ParserException(ErrorMessages.REPEATED_INGREDIENT_ARGUMENT); @@ -420,6 +429,7 @@ private static void detectErrorPostIngredientParse( /** * Converts text of price to float while also checking if the price input is within reasonable range + * * @param priceText text input for price argument * @return price in float format * @throws ParserException if price is not within reasonable format and range @@ -463,6 +473,7 @@ public static float parsePriceToFloat(String priceText) throws ParserException { /** * Checks in the menu if the dish name already exists. + * * @param inputDishName dish name entered by the user * @param menu contains all the existing Dishes * @return true if dish name already exists in menu, false otherwise @@ -486,6 +497,7 @@ public static boolean isRepeatedDishName(String inputDishName, Menu menu) throws /** * Checks in the ingredient list if the ingredient name already exists. + * * @param inputName dish name entered by the user * @param ingredients contains all the existing Ingredients * @return true if ingredient name already exists in menu, false otherwise @@ -511,6 +523,7 @@ public static boolean isRepeatedIngredientName(String inputName, ArrayList 1 match of the argument, false otherwise @@ -552,17 +566,18 @@ public static boolean isRepeatedArgument(String inputText, String argument) { //@@author NaychiMin /** - * Parses arguments in the context of the ListIngredient command. - * @param menu menu of the current session - * @param arguments string that matches group arguments - * @return the prepared command + * Parses arguments in the context of the ListIngredient command. + * + * @param menu menu of the current session + * @param arguments string that matches group arguments + * @return the prepared command */ private static Command prepareListIngredient(Menu menu, String arguments, Ui ui) { final Pattern prepareListPattern = Pattern.compile(LIST_INGREDIENTS_ARGUMENT_STRING); Matcher matcher = prepareListPattern.matcher(arguments.trim()); if (!matcher.matches()) { - logger.warning("Unmatching regex!"); + logger.warning("Unmatched regex!"); return new IncorrectCommand(ErrorMessages.MISSING_ARGUMENT_FOR_LIST_INGREDIENTS + ListIngredientCommand.MESSAGE_USAGE, ui); } @@ -598,7 +613,7 @@ private static Command prepareDelete(Menu menu, String arguments, Ui ui) { // Checks whether the overall pattern of delete price arguments is correct if (!matcher.matches()) { - logger.warning("Unmatching regex!"); + logger.warning("Unmatched regex!"); return new IncorrectCommand(ErrorMessages.MISSING_ARGUMENT_FOR_DELETE, ui); } @@ -621,7 +636,7 @@ private static Command prepareBuyIngredient(String arguments, Ui ui, Pantry pant Matcher matcher = buyIngredientArgumentsPattern.matcher(arguments.trim()); if (!matcher.matches()) { - logger.warning("Unmatching regex!"); + logger.warning("Unmatched regex!"); return new IncorrectCommand(ErrorMessages.INVALID_ARGUMENT_FOR_BUY_INGREDIENT + BuyIngredientCommand.MESSAGE_USAGE, ui); } @@ -651,6 +666,7 @@ public static boolean isInvalidQty(int ingredientQty) { public static void checkForMismatchUnit(Menu menu, Ingredient newIngredient) throws ParserException { logger.info("Checking for mismatched units..."); ArrayList dishArrayList = menu.getMenuItemsList(); + for (Dish dish : dishArrayList) { traverseIngredientsOfDish(newIngredient, dish); } @@ -658,6 +674,7 @@ public static void checkForMismatchUnit(Menu menu, Ingredient newIngredient) thr private static void traverseIngredientsOfDish(Ingredient newIngredient, Dish dish) throws ParserException { ArrayList ingredientArrayList = dish.getIngredients(); + for (Ingredient currentIngredient : ingredientArrayList) { logger.info("Comparing name: " + newIngredient.getName() + " and " + currentIngredient.getName()); compareIngredientName(newIngredient, currentIngredient); @@ -685,6 +702,7 @@ private static void compareUnits(Ingredient newIngredient, Ingredient currentIng //@@author ziyi105 /** * Check whether a text contains special character + * * @param text text to be checked * @return true if it contains special character, false otherwise */ diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 4368ea1bb1..93d5703ec1 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -87,11 +87,11 @@ private static void checkUnitValidity(String unit) throws Exception { throw new Exception(); } } - //@@author //@@author ziyi105 /** * Decodes raw string from pantry stock data file and create ingredient object from the data + * * @param encodedPantryStock raw string from pantry stock data file * @return a new pantry object with data from the pantry stock data file */ @@ -150,6 +150,7 @@ private static boolean isValidUnit(String unit) { /** * Checks whether the pantry stock is in the format of ingredient name | quantity (int) | unit + * * @param decodedPantryStock string array of the raw data string from pantry stock data file * split with "|" * @return true if the format is correct, false otherwise @@ -267,14 +268,12 @@ private static boolean isCompleteStatusAccurate(String orderLine, String complet return false; } - //@@author Cazh1 /** * Increases the size of the orderlist when there is gap between the previous order and the next * * @param orderLists The current partially filled ArrayList of OrderList * @param day The day of the next order - * @return orderLists after filling in the gaps */ private static void fillOrderListSize(ArrayList orderLists, int day) { while (orderLists.size() <= day) { diff --git a/src/main/java/seedu/cafectrl/storage/Encoder.java b/src/main/java/seedu/cafectrl/storage/Encoder.java index fb0fb7fc0a..ca134a9949 100644 --- a/src/main/java/seedu/cafectrl/storage/Encoder.java +++ b/src/main/java/seedu/cafectrl/storage/Encoder.java @@ -22,7 +22,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()); + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); //@@author Cazh1 /** @@ -90,6 +90,7 @@ private static StringBuilder encodeIngredientList(ArrayList ingredie //@@author ziyi105 /** * Encodes the pantry stock into format ingredient name | quantity | unit + * * @param pantry the pantry from current session * @return an arrayList of string of ecoded pantry stock */ @@ -97,6 +98,7 @@ public static ArrayList encodePantryStock(Pantry pantry) { // Convert pantry stock to a list of String ArrayList pantryStockInString = new ArrayList<>(); ArrayList pantryStock = pantry.getPantryStock(); + for (Ingredient ingredient : pantryStock) { StringBuilder encodedIngredient = new StringBuilder(); encodedIngredient.append(ingredient.getName().trim()); @@ -127,11 +129,14 @@ public static ArrayList encodeSales(Sales sales) { for (int day = 0; day < orderLists.size(); day++) { logger.info("Encoding sales of day " + day); + //get orderList for each day from list of sales OrderList orderList = sales.getOrderList(day); + //get order from each orderList obtained for (Order order : orderList.getOrderList()) { StringBuilder orderString = new StringBuilder(); + //day of each orderList is index + 1 orderString.append((day + 1) + DIVIDER); orderString.append(order.getDishName() + DIVIDER); @@ -162,6 +167,7 @@ public static ArrayList encodeSales(Sales sales) { private static ArrayList encodeLastSalesDay(ArrayList encodedList, OrderList orderList, int day) { if (orderList.getSize() == 0) { StringBuilder orderString = new StringBuilder(); + //day of each orderList is index + 1 orderString.append((day + 1) + DIVIDER); orderString.append(NULL_ORDER_DAY); diff --git a/src/main/java/seedu/cafectrl/storage/Storage.java b/src/main/java/seedu/cafectrl/storage/Storage.java index 3979aa8b26..3a6e800ff4 100644 --- a/src/main/java/seedu/cafectrl/storage/Storage.java +++ b/src/main/java/seedu/cafectrl/storage/Storage.java @@ -20,15 +20,15 @@ */ public class Storage { - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); - protected FileManager fileManager; - protected Ui ui; - private boolean isHashingEnabled = true; + private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private final boolean isHashingEnabled = true; private boolean isMenuTampered = false; private boolean isOrdersTampered = false; private boolean isPantryStockTampered = false; private boolean isHashStringTampered = false; private boolean isTamperedMessagePrinted = false; + protected FileManager fileManager; + protected Ui ui; public Storage (Ui ui) { this.fileManager = new FileManager(ui); @@ -36,7 +36,6 @@ public Storage (Ui ui) { } //@@author Cazh1 - private boolean isFileEmpty(ArrayList encodedStringArrayList) { return encodedStringArrayList.isEmpty(); } @@ -146,6 +145,7 @@ private void saveMenu(Menu menu) throws IOException { //@@author ziyi105 /** * Read and decode pantryStock data from text file and pass it to the menu + * * @return pantryStock with data from the file */ public Pantry loadPantryStock() { @@ -165,6 +165,7 @@ public Pantry loadPantryStock() { /** * Encode and write the data from PantryStock to the text file + * * @param pantry pantry from current session * @throws IOException if the file is not found in the specified file path */ @@ -209,6 +210,7 @@ private void saveOrderList(Sales sales) throws IOException { //@@author ziyi105 /** * Encode and write the data from menu, orderList and pantry to the respective text files + * * @param menu menu from current session * @param sales sale object from current session * @param pantry pantry from current session From e42c6d7b37e1a997b6b15a031ec2706a6a6b758f Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 14:39:04 +0800 Subject: [PATCH 05/14] Update coding standard in Ui.java --- src/main/java/seedu/cafectrl/ui/Ui.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java index a58bf975a1..fb3b9402c9 100644 --- a/src/main/java/seedu/cafectrl/ui/Ui.java +++ b/src/main/java/seedu/cafectrl/ui/Ui.java @@ -96,7 +96,7 @@ public void showDishPrice(Dish dish) { showToUser(dishPriceString, Messages.INGREDIENTS_CORNER); } - //@@author + //@@author ShaniceTang /** * Shows delete message to user * @@ -122,6 +122,7 @@ public void showToUser(String... message) { /** * Shows menu to user is table format + * * @param dishName * @param dishPrice */ @@ -132,6 +133,7 @@ public void formatListMenu(String dishName, String dishPrice) { /** * show edit price message to user + * * @param menuItem menuItem that has been modified */ public void showEditPriceMessage(String menuItem) { @@ -283,8 +285,4 @@ public void showPreviousDay() { public void showNextDay() { showToUser(Messages.NEXT_DAY_COMMAND_MESSAGE); } - - public void showDecodedInvalidDish(String dishName) { - showToUser(dishName + Messages.INVALID_DISH + dishName); - } } From 28d2c33b44965eb87ea0643fdb42fbe907dcd64c Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 14:49:02 +0800 Subject: [PATCH 06/14] Update according to checkStyle --- src/main/java/seedu/cafectrl/command/EditPriceCommand.java | 4 ++-- src/main/java/seedu/cafectrl/data/Chef.java | 1 - src/main/java/seedu/cafectrl/data/CurrentDate.java | 4 ++-- src/main/java/seedu/cafectrl/parser/Parser.java | 1 - src/main/java/seedu/cafectrl/storage/Storage.java | 5 +++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java index 7ef5f0a436..c014e7cfa3 100644 --- a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java +++ b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java @@ -19,10 +19,10 @@ public class EditPriceCommand extends Command { + "Example: edit_price dish/1 price/4.50"; private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); - private final int menuID; - private final float newPrice; protected Menu menu; protected Ui ui; + private final int menuID; + private final float newPrice; public EditPriceCommand(int menuID, float newPrice, Menu menu, Ui ui) { this.menuID = menuID; diff --git a/src/main/java/seedu/cafectrl/data/Chef.java b/src/main/java/seedu/cafectrl/data/Chef.java index d6799ee974..7f00f122f6 100644 --- a/src/main/java/seedu/cafectrl/data/Chef.java +++ b/src/main/java/seedu/cafectrl/data/Chef.java @@ -3,7 +3,6 @@ import seedu.cafectrl.CafeCtrl; import seedu.cafectrl.ui.Ui; -import java.text.DecimalFormat; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/src/main/java/seedu/cafectrl/data/CurrentDate.java b/src/main/java/seedu/cafectrl/data/CurrentDate.java index 42f4dd06ab..8eb7ba9350 100644 --- a/src/main/java/seedu/cafectrl/data/CurrentDate.java +++ b/src/main/java/seedu/cafectrl/data/CurrentDate.java @@ -3,8 +3,8 @@ import java.util.ArrayList; public class CurrentDate { - private final static int ZERO = 0; - private final static int ONE = 1; + private static final int ZERO = 0; + private static final int ONE = 1; private int currentDay; public CurrentDate() { diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java index 67ffd72a22..49aed837a8 100644 --- a/src/main/java/seedu/cafectrl/parser/Parser.java +++ b/src/main/java/seedu/cafectrl/parser/Parser.java @@ -161,7 +161,6 @@ public Command parseCommand(Menu menu, String userInput, Ui ui, } } - /** All prepareCommand Classes **/ //@@author Cazh1 /** * Prepares the ListMenuCommand diff --git a/src/main/java/seedu/cafectrl/storage/Storage.java b/src/main/java/seedu/cafectrl/storage/Storage.java index 3a6e800ff4..23e11b5392 100644 --- a/src/main/java/seedu/cafectrl/storage/Storage.java +++ b/src/main/java/seedu/cafectrl/storage/Storage.java @@ -21,14 +21,15 @@ public class Storage { private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + protected FileManager fileManager; + protected Ui ui; private final boolean isHashingEnabled = true; private boolean isMenuTampered = false; private boolean isOrdersTampered = false; private boolean isPantryStockTampered = false; private boolean isHashStringTampered = false; private boolean isTamperedMessagePrinted = false; - protected FileManager fileManager; - protected Ui ui; + public Storage (Ui ui) { this.fileManager = new FileManager(ui); From 88182f0af24e86d5e888971b44443db2c02e125f Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 15:16:30 +0800 Subject: [PATCH 07/14] Add a line after loading data --- src/main/java/seedu/cafectrl/storage/Decoder.java | 5 +++++ src/main/java/seedu/cafectrl/storage/Storage.java | 9 +++++++++ src/main/java/seedu/cafectrl/ui/Messages.java | 3 +++ 3 files changed, 17 insertions(+) diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index 93d5703ec1..a026b5cb87 100644 --- a/src/main/java/seedu/cafectrl/storage/Decoder.java +++ b/src/main/java/seedu/cafectrl/storage/Decoder.java @@ -11,6 +11,7 @@ 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; @@ -41,10 +42,12 @@ public class Decoder { public static Menu decodeMenuData(ArrayList textLines) { logger.info("Decoding menu.txt to Menu..."); ArrayList menuDishList = new ArrayList<>(); + for(String dishString : textLines) { logger.info("Line to decode: " + dishString); decodeDishString(dishString, menuDishList); } + return new Menu(menuDishList); } @@ -135,6 +138,7 @@ && isValidUnit(unit)) { ui.showToUser(ErrorMessages.ERROR_IN_PANTRY_STOCK_DATA + encodedData); } } + return new Pantry(ui, pantryStock); } @@ -193,6 +197,7 @@ public static Sales decodeSales(ArrayList textLines, Menu menu) { } decodeSalesData(line, orderLists, menu); } + if (orderLists.isEmpty()) { return new Sales(); } diff --git a/src/main/java/seedu/cafectrl/storage/Storage.java b/src/main/java/seedu/cafectrl/storage/Storage.java index 23e11b5392..009e2f9a36 100644 --- a/src/main/java/seedu/cafectrl/storage/Storage.java +++ b/src/main/java/seedu/cafectrl/storage/Storage.java @@ -129,6 +129,9 @@ public Menu loadMenu() { logger.log(Level.WARNING, "menu.txt not found!\n" + e.getMessage(), e); ui.showToUser(ErrorMessages.MENU_FILE_NOT_FOUND_MESSAGE, System.lineSeparator()); return new Menu(); + } finally { + ui.showToUser(Messages.DONE_LOADING_MENU); + ui.printLine(); } } @@ -161,6 +164,9 @@ public Pantry loadPantryStock() { } catch (FileNotFoundException e) { ui.showToUser(ErrorMessages.PANTRY_FILE_NOT_FOUND_MESSAGE, System.lineSeparator()); return new Pantry(ui); + } finally { + ui.showToUser(Messages.DONE_LOADING_PANTRY_STOCK); + ui.printLine(); } } @@ -194,6 +200,9 @@ public Sales loadOrderList(Menu menu) { logger.log(Level.WARNING, "orders.txt not found!\n" + e.getMessage(), e); ui.showToUser(ErrorMessages.ORDER_LIST_FILE_NOT_FOUND_MESSAGE, System.lineSeparator()); return new Sales(); + } finally { + ui.showToUser(Messages.DONE_LOADING_SALES); + ui.printLine(); } } diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java index 659f255948..fc1d87b044 100644 --- a/src/main/java/seedu/cafectrl/ui/Messages.java +++ b/src/main/java/seedu/cafectrl/ui/Messages.java @@ -108,4 +108,7 @@ public class Messages { + "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 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!"; } From 655658556e4d743e24b1d1842d6dac249a368791 Mon Sep 17 00:00:00 2001 From: ziyi105 <82555990+ziyi105@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:17:30 +0800 Subject: [PATCH 08/14] Update src/main/java/seedu/cafectrl/data/CurrentDate.java Co-authored-by: Dexter <35828587+DextheChik3n@users.noreply.github.com> --- src/main/java/seedu/cafectrl/data/CurrentDate.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/CurrentDate.java b/src/main/java/seedu/cafectrl/data/CurrentDate.java index 8eb7ba9350..05a4e50339 100644 --- a/src/main/java/seedu/cafectrl/data/CurrentDate.java +++ b/src/main/java/seedu/cafectrl/data/CurrentDate.java @@ -3,8 +3,10 @@ import java.util.ArrayList; public class CurrentDate { - private static final int ZERO = 0; - private static final int ONE = 1; + private static final int MIN_ORDER_LIST_SIZE = 0; + private static final int DAY_BASE_NUMBER = 0; + private static final int DAY_OFFSET = 1; + private static final int ORDER_LIST_SIZE_OFFSET = 1; private int currentDay; public CurrentDate() { From b721daa466f76169044b6f859a8e282cb31e7b69 Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 15:19:10 +0800 Subject: [PATCH 09/14] Assign variable to obj.name --- src/main/java/seedu/cafectrl/data/dish/Ingredient.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java index 5226496a86..c6bbfddef1 100644 --- a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java +++ b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java @@ -40,13 +40,15 @@ public String toString() { /** * Compare the name of this ingredient to the other ingredient + * * @param obj the other ingredient to be compared with * @return true if they have the same name, false otherwise */ @Override public boolean equals(Object obj) { if (obj instanceof Ingredient) { - return this.name.equals(((Ingredient) obj).name); + String otherName = ((Ingredient) obj).name; + return this.name.equals(otherName); } return false; } From ce52191b217693cf4050ccd2219018c379d9c9eb Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 15:26:52 +0800 Subject: [PATCH 10/14] Update variable names --- src/main/java/seedu/cafectrl/data/CurrentDate.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/CurrentDate.java b/src/main/java/seedu/cafectrl/data/CurrentDate.java index 05a4e50339..3a0f502233 100644 --- a/src/main/java/seedu/cafectrl/data/CurrentDate.java +++ b/src/main/java/seedu/cafectrl/data/CurrentDate.java @@ -10,21 +10,21 @@ public class CurrentDate { private int currentDay; public CurrentDate() { - currentDay = ZERO; + currentDay = DAY_BASE_NUMBER; } public CurrentDate(int day) { - currentDay = day - ONE; + currentDay = day - DAY_OFFSET; } public CurrentDate(Sales sales) { setDate(sales); } public void nextDay() { - currentDay += ONE; + currentDay += DAY_OFFSET; } public void previousDay() { - currentDay -= ONE; + currentDay -= DAY_OFFSET; } public int getCurrentDay() { @@ -40,10 +40,10 @@ public void setDate(Sales sales) { ArrayList orderLists = sales.getOrderLists(); int orderListsSize = orderLists.size(); - if (orderListsSize > ZERO) { - currentDay = orderListsSize - ONE; + if (orderListsSize > MIN_ORDER_LIST_SIZE) { + currentDay = orderListsSize - ORDER_LIST_SIZE_OFFSET; } else { - currentDay = ZERO; + currentDay = DAY_BASE_NUMBER; } } } From 0e8a2c018d16af4f50f15265680f6a4d94cd1d4f Mon Sep 17 00:00:00 2001 From: ziyi105 Date: Mon, 13 Nov 2023 15:34:03 +0800 Subject: [PATCH 11/14] Remove unused import --- src/main/java/seedu/cafectrl/storage/Decoder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/cafectrl/storage/Decoder.java b/src/main/java/seedu/cafectrl/storage/Decoder.java index da71314f65..330af437b3 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; From f300a74888dfd55e3b119d86a38831a81fd2eb71 Mon Sep 17 00:00:00 2001 From: ziyi105 <82555990+ziyi105@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:47:04 +0800 Subject: [PATCH 12/14] Change order of variable in Pantry.java --- 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 e8361f8a5b..f3bf94521f 100644 --- a/src/main/java/seedu/cafectrl/data/Pantry.java +++ b/src/main/java/seedu/cafectrl/data/Pantry.java @@ -13,10 +13,10 @@ public class Pantry { private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); - public static final int DEFAULT_ORDER_QTY = 1; private final Ui ui; private ArrayList pantryStock; + public static final int DEFAULT_ORDER_QTY = 1; //@@author NaychiMin public Pantry(Ui ui, ArrayList pantryStock) { From da86bbe26b920cd186b248b9182e4bdef393712a Mon Sep 17 00:00:00 2001 From: ziyi105 <82555990+ziyi105@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:50:42 +0800 Subject: [PATCH 13/14] Update Pantry.java --- src/main/java/seedu/cafectrl/data/Pantry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java index f3bf94521f..d38ae3987c 100644 --- a/src/main/java/seedu/cafectrl/data/Pantry.java +++ b/src/main/java/seedu/cafectrl/data/Pantry.java @@ -14,9 +14,9 @@ public class Pantry { private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Ui ui; - - private ArrayList pantryStock; + public static final int DEFAULT_ORDER_QTY = 1; + private ArrayList pantryStock; //@@author NaychiMin public Pantry(Ui ui, ArrayList pantryStock) { From e594262e3d147bd3daf6ff368bd7a71518e02c9c Mon Sep 17 00:00:00 2001 From: ziyi105 <82555990+ziyi105@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:53:24 +0800 Subject: [PATCH 14/14] Update Pantry.java --- src/main/java/seedu/cafectrl/data/Pantry.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java index d38ae3987c..f32324d67c 100644 --- a/src/main/java/seedu/cafectrl/data/Pantry.java +++ b/src/main/java/seedu/cafectrl/data/Pantry.java @@ -11,11 +11,10 @@ import java.util.logging.Logger; public class Pantry { - + public static final int DEFAULT_ORDER_QTY = 1; private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName()); - private final Ui ui; - public static final int DEFAULT_ORDER_QTY = 1; + private final Ui ui; private ArrayList pantryStock; //@@author NaychiMin