From 3c7332d284073034d995d3b9d4ababee77f980f5 Mon Sep 17 00:00:00 2001 From: ShaniceTang Date: Fri, 10 Nov 2023 11:52:20 +0800 Subject: [PATCH] Improve code quality --- src/main/java/seedu/cafectrl/CafeCtrl.java | 3 ++- src/main/java/seedu/cafectrl/command/AddDishCommand.java | 3 +-- src/main/java/seedu/cafectrl/command/AddOrderCommand.java | 3 +-- .../java/seedu/cafectrl/command/BuyIngredientCommand.java | 5 ++--- src/main/java/seedu/cafectrl/command/DeleteDishCommand.java | 2 +- src/main/java/seedu/cafectrl/command/IncorrectCommand.java | 2 +- .../java/seedu/cafectrl/command/ListIngredientCommand.java | 2 +- src/main/java/seedu/cafectrl/command/ListMenuCommand.java | 2 +- .../java/seedu/cafectrl/command/ListSaleByDayCommand.java | 2 +- src/main/java/seedu/cafectrl/command/ListTotalSales.java | 3 ++- src/main/java/seedu/cafectrl/command/NextDayCommand.java | 3 +-- src/main/java/seedu/cafectrl/command/PreviousDayCommand.java | 2 +- .../java/seedu/cafectrl/command/ViewTotalStockCommand.java | 4 ++-- src/main/java/seedu/cafectrl/data/Chef.java | 2 +- src/main/java/seedu/cafectrl/data/Menu.java | 2 +- src/main/java/seedu/cafectrl/data/OrderList.java | 2 +- src/main/java/seedu/cafectrl/data/Pantry.java | 3 ++- src/main/java/seedu/cafectrl/data/Sales.java | 5 +++-- src/main/java/seedu/cafectrl/storage/FileManager.java | 3 ++- src/main/java/seedu/cafectrl/storage/Storage.java | 3 ++- 20 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java index 24e5803860..2e22d44c64 100644 --- a/src/main/java/seedu/cafectrl/CafeCtrl.java +++ b/src/main/java/seedu/cafectrl/CafeCtrl.java @@ -22,6 +22,8 @@ * Initializes the application and starts the interaction with the user. */ public class CafeCtrl { + + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Ui ui; private Menu menu; private Command command; @@ -29,7 +31,6 @@ public class CafeCtrl { private Sales sales; private CurrentDate currentDate; private Storage storage; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); /** * Private constructor for the CafeCtrl class, used for initializing the user interface and menu list. diff --git a/src/main/java/seedu/cafectrl/command/AddDishCommand.java b/src/main/java/seedu/cafectrl/command/AddDishCommand.java index a7e797a2bf..da6f0fdb40 100644 --- a/src/main/java/seedu/cafectrl/command/AddDishCommand.java +++ b/src/main/java/seedu/cafectrl/command/AddDishCommand.java @@ -17,10 +17,9 @@ public class AddDishCommand extends Command { + "[, ingredient/INGREDIENT2_NAME, qty/INGREDIENT2_QTY...]\n" + "Example:" + COMMAND_WORD + " name/chicken rice price/3.00 ingredient/rice qty/200g, ingredient/chicken qty/100g"; - + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Menu menu; protected Ui ui; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Dish dish; public AddDishCommand(Dish dish, Menu menu, Ui ui) { diff --git a/src/main/java/seedu/cafectrl/command/AddOrderCommand.java b/src/main/java/seedu/cafectrl/command/AddOrderCommand.java index 57bb83b238..ceda5c53bf 100644 --- a/src/main/java/seedu/cafectrl/command/AddOrderCommand.java +++ b/src/main/java/seedu/cafectrl/command/AddOrderCommand.java @@ -21,13 +21,12 @@ public class AddOrderCommand extends Command { + " name/DISH_NAME qty/QUANTITY\n" + "Example: " + COMMAND_WORD + "name/chicken rice qty/2"; - + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Pantry pantry; protected OrderList orderList; protected Menu menu; private final Ui ui; private final Order order; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final DecimalFormat dollarValue = new DecimalFormat("0.00"); public AddOrderCommand(Order order, Ui ui, Pantry pantry, OrderList orderList, Menu menu) { diff --git a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java index ae4f6d0f10..5ef5e49028 100644 --- a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java +++ b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java @@ -22,14 +22,13 @@ public class BuyIngredientCommand extends Command { + "[, ingredient/INGREDIENT2_NAME, qty/INGREDIENT2_QTY...]\n" + "Example:" + COMMAND_WORD + " ingredient/milk qty/200ml, ingredient/chicken qty/100g"; - + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final int FIRST_INDEX = 0; protected Ui ui; protected Pantry pantry; private ArrayList ingredients; private ArrayList ingredientsToBePrinted = new ArrayList<>(); private String ingredientString = ""; // Used to store the message about the bought ingredients - private int FIRST_INDEX = 0; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); /** * Constructs a BuyIngredientCommand with the specified ingredients, user interface, and pantry. diff --git a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java index 7f93c781d9..da29cd2d09 100644 --- a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java +++ b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java @@ -20,9 +20,9 @@ public class DeleteDishCommand extends Command { + "Parameters: INDEX\n" + "Example: " + COMMAND_WORD + " 1"; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Menu menu; protected Ui ui; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public DeleteDishCommand(int listIndex, Menu menu, Ui ui) { this.index = listIndex; diff --git a/src/main/java/seedu/cafectrl/command/IncorrectCommand.java b/src/main/java/seedu/cafectrl/command/IncorrectCommand.java index ba9dfac282..fd023d0011 100644 --- a/src/main/java/seedu/cafectrl/command/IncorrectCommand.java +++ b/src/main/java/seedu/cafectrl/command/IncorrectCommand.java @@ -9,9 +9,9 @@ * Represents an incorrect command. Upon execution, produces some feedback to the user. */ public class IncorrectCommand extends Command{ + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public final String feedbackToUser; protected Ui ui; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public IncorrectCommand(String feedbackToUser, Ui ui) { this.feedbackToUser = feedbackToUser; diff --git a/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java index 2b139e33d1..c122ec4115 100644 --- a/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java +++ b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java @@ -20,9 +20,9 @@ public class ListIngredientCommand extends Command { + "Parameters: DISH_INDEX\n" + "Example: " + COMMAND_WORD + " 1"; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Ui ui; protected Menu menu; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public ListIngredientCommand(int listIndex, Menu menu, Ui ui) { this.index = listIndex; diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java index 05ac5facac..7dcdc5b520 100644 --- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java +++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java @@ -17,9 +17,9 @@ public class ListMenuCommand extends Command { + COMMAND_WORD; private static final DecimalFormat dollarValue = new DecimalFormat("0.00"); + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Menu menu; private final Ui ui; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); /** * Constructor for the ListMenuCommand diff --git a/src/main/java/seedu/cafectrl/command/ListSaleByDayCommand.java b/src/main/java/seedu/cafectrl/command/ListSaleByDayCommand.java index ea3a806453..9ad621276f 100644 --- a/src/main/java/seedu/cafectrl/command/ListSaleByDayCommand.java +++ b/src/main/java/seedu/cafectrl/command/ListSaleByDayCommand.java @@ -15,11 +15,11 @@ public class ListSaleByDayCommand extends Command { + COMMAND_WORD + " day/DAY_TO_DISPLAY\n" + "Example: " + COMMAND_WORD + " day/1"; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final int day; private final Ui ui; private final Sales sales; private final Menu menu; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public ListSaleByDayCommand(int day, Ui ui, Sales sales, Menu menu) { this.day = day; diff --git a/src/main/java/seedu/cafectrl/command/ListTotalSales.java b/src/main/java/seedu/cafectrl/command/ListTotalSales.java index 0d0cf78890..53a2c05145 100644 --- a/src/main/java/seedu/cafectrl/command/ListTotalSales.java +++ b/src/main/java/seedu/cafectrl/command/ListTotalSales.java @@ -10,10 +10,11 @@ public class ListTotalSales extends Command { public static final String COMMAND_WORD = "list_total_sales"; public static final String MESSAGE_USAGE = "To show sales for all days:\n" + COMMAND_WORD; + + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private Sales sales; private Ui ui; private Menu menu; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public ListTotalSales(Sales sales, Ui ui, Menu menu) { this.sales = sales; diff --git a/src/main/java/seedu/cafectrl/command/NextDayCommand.java b/src/main/java/seedu/cafectrl/command/NextDayCommand.java index 7b3476a386..ebeba34d99 100644 --- a/src/main/java/seedu/cafectrl/command/NextDayCommand.java +++ b/src/main/java/seedu/cafectrl/command/NextDayCommand.java @@ -9,15 +9,14 @@ import java.util.logging.Logger; public class NextDayCommand extends Command { - public static final String COMMAND_WORD = "next_day"; public static final String MESSAGE_USAGE = "To travel to next day:\n" + COMMAND_WORD; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private final Ui ui; private final Sales sales; private final CurrentDate currentDate; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public NextDayCommand(Ui ui, Sales sales, CurrentDate currentDate) { this.ui = ui; diff --git a/src/main/java/seedu/cafectrl/command/PreviousDayCommand.java b/src/main/java/seedu/cafectrl/command/PreviousDayCommand.java index 4f3a35bc62..1fe391797b 100644 --- a/src/main/java/seedu/cafectrl/command/PreviousDayCommand.java +++ b/src/main/java/seedu/cafectrl/command/PreviousDayCommand.java @@ -10,9 +10,9 @@ public class PreviousDayCommand extends Command{ public static final String COMMAND_WORD = "previous_day"; public static final String MESSAGE_USAGE = "To go back to previous day:\n" + COMMAND_WORD; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Ui ui; protected CurrentDate currentDate; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public PreviousDayCommand(Ui ui, CurrentDate currentDate) { this.ui = ui; diff --git a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java index da82c1ee23..7c87ed8790 100644 --- a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java +++ b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java @@ -11,13 +11,13 @@ //@@author ShaniceTang public class ViewTotalStockCommand extends Command { - public static final String COMMAND_WORD = "view_stock"; public static final String MESSAGE_USAGE = "To view pantry stock:\n" + COMMAND_WORD; + + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected Ui ui; protected Pantry pantry; private ArrayList pantryStock; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public ViewTotalStockCommand(Pantry pantry, Ui ui) { this.pantry = pantry; diff --git a/src/main/java/seedu/cafectrl/data/Chef.java b/src/main/java/seedu/cafectrl/data/Chef.java index 8cdbb47afb..1a3c6f6393 100644 --- a/src/main/java/seedu/cafectrl/data/Chef.java +++ b/src/main/java/seedu/cafectrl/data/Chef.java @@ -9,12 +9,12 @@ public class Chef { + private static 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"); - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public Chef(Order order, Pantry pantry, Ui ui) { diff --git a/src/main/java/seedu/cafectrl/data/Menu.java b/src/main/java/seedu/cafectrl/data/Menu.java index 70773e4119..3fd6d9e9cf 100644 --- a/src/main/java/seedu/cafectrl/data/Menu.java +++ b/src/main/java/seedu/cafectrl/data/Menu.java @@ -8,8 +8,8 @@ import java.util.logging.Logger; public class Menu { - private ArrayList menuItems; private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private ArrayList menuItems; public Menu() { this.menuItems = new ArrayList<>(); diff --git a/src/main/java/seedu/cafectrl/data/OrderList.java b/src/main/java/seedu/cafectrl/data/OrderList.java index b299d717e0..73879ef836 100644 --- a/src/main/java/seedu/cafectrl/data/OrderList.java +++ b/src/main/java/seedu/cafectrl/data/OrderList.java @@ -14,9 +14,9 @@ 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 ArrayList orderList; private float totalOrderListCost; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); /** * Constructs an empty OrderList with no orders and zero total order cost. diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java index f16460cef1..d3ac04ebeb 100644 --- a/src/main/java/seedu/cafectrl/data/Pantry.java +++ b/src/main/java/seedu/cafectrl/data/Pantry.java @@ -11,9 +11,10 @@ import java.util.logging.Logger; public class Pantry { + + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); private ArrayList pantryStock; private Ui ui; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); //@@author NaychiMin public Pantry(Ui ui, ArrayList pantryStock) { diff --git a/src/main/java/seedu/cafectrl/data/Sales.java b/src/main/java/seedu/cafectrl/data/Sales.java index 02388c8b1b..3a6ff14099 100644 --- a/src/main/java/seedu/cafectrl/data/Sales.java +++ b/src/main/java/seedu/cafectrl/data/Sales.java @@ -12,10 +12,11 @@ * The Sales class represents sales data over a period of time, maintaining a collection of order lists. */ public class Sales { + + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private static final int DAY_DISPLAY_OFFSET = 1; private static ArrayList orderLists; private int daysAccounted; - private final int DAY_DISPLAY_OFFSET = 1; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public Sales() { this.orderLists = new ArrayList<>(); diff --git a/src/main/java/seedu/cafectrl/storage/FileManager.java b/src/main/java/seedu/cafectrl/storage/FileManager.java index 74f67f7206..11062acf98 100644 --- a/src/main/java/seedu/cafectrl/storage/FileManager.java +++ b/src/main/java/seedu/cafectrl/storage/FileManager.java @@ -19,8 +19,9 @@ * Manage everything related to file such as writing, reading, opening and creating file */ public class FileManager { - private final Ui ui; + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); + private final Ui ui; public FileManager(Ui ui) { this.ui = ui; diff --git a/src/main/java/seedu/cafectrl/storage/Storage.java b/src/main/java/seedu/cafectrl/storage/Storage.java index e555eac010..9e1bc5d9be 100644 --- a/src/main/java/seedu/cafectrl/storage/Storage.java +++ b/src/main/java/seedu/cafectrl/storage/Storage.java @@ -18,9 +18,10 @@ * Handles loading and saving data for menu, orderList, pantryStock */ public class Storage { + + private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); protected FileManager fileManager; protected Ui ui; - private static Logger logger = Logger.getLogger(CafeCtrl.class.getName()); public Storage (Ui ui) { this.fileManager = new FileManager(ui);