Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General coding standard check #351

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/main/java/seedu/cafectrl/CafeCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -59,6 +58,7 @@ private CafeCtrl() {
private void run() {
ui.showWelcome();
ui.printLine();

do {
try {
String fullUserInput = ui.receiveUserInput();
Expand All @@ -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();
Expand All @@ -94,6 +95,4 @@ public static void main(String[] args) {
CafeCtrl cafeCtrl = new CafeCtrl();
cafeCtrl.run();
}

}

2 changes: 1 addition & 1 deletion src/main/java/seedu/cafectrl/command/EditPriceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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());
private static final Logger logger = Logger.getLogger(CafeCtrl.class.getName());
protected Menu menu;
protected Ui ui;
private final int menuID;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/cafectrl/command/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -22,6 +21,7 @@ public HelpCommand(Ui ui) {
@Override
public void execute() {
logger.info("Executing HelpCommand...");

ui.printLine();
ui.showHelp();
}
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/seedu/cafectrl/data/Chef.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
import seedu.cafectrl.CafeCtrl;
import seedu.cafectrl.ui.Ui;

import java.text.DecimalFormat;
import java.util.logging.Level;
import java.util.logging.Logger;


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;
Expand All @@ -28,9 +24,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);
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/seedu/cafectrl/data/CurrentDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
import java.util.ArrayList;

public class CurrentDate {
private static final int ZERO = 0;
private static final int ONE = 1;
ziyi105 marked this conversation as resolved.
Show resolved Hide resolved
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() {
Expand All @@ -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<OrderList> orderLists = sales.getOrderLists();
int orderListsSize = orderLists.size();
if (orderListsSize > 0) {
currentDay = orderListsSize - 1;

if (orderListsSize > ZERO) {
currentDay = orderListsSize - ONE;
} else {
currentDay = 0;
currentDay = ZERO;
}
}
}
39 changes: 26 additions & 13 deletions src/main/java/seedu/cafectrl/data/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dish> menuItems;

public Menu() {
Expand All @@ -22,9 +22,11 @@ public Menu(ArrayList<Dish> menuItems) {
public ArrayList<Dish> getMenuItemsList() {
return menuItems;
}

public int getSize() {
return menuItems.size();
}

public Dish getDishFromId(int menuID) {
return menuItems.get(menuID);
}
Expand All @@ -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
/**
Expand All @@ -76,4 +67,26 @@ public ArrayList<Order> 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);
}
}
7 changes: 4 additions & 3 deletions src/main/java/seedu/cafectrl/data/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ public class Order {
private final Dish orderedDish;
private int dishQty;
private final ArrayList<Ingredient> 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;
Expand Down Expand Up @@ -59,6 +59,7 @@ private ArrayList<Ingredient> setIngredientList() {
String ingredientName = ingredient.getName();
int ingredientQty = ingredient.getQty() * dishQty;
String ingredientUnit = ingredient.getUnit();

dishIngredient.add(new Ingredient(ingredientName, ingredientQty, ingredientUnit));
}
return dishIngredient;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/cafectrl/data/OrderList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Order> orderList;
private float totalOrderListCost;

Expand Down Expand Up @@ -78,6 +78,7 @@ public void printOrderList(Menu menu, Ui ui) {
*/
private void aggregateOrder(Order order, ArrayList<Order> aggregatedOrders) {
logger.info("Aggregating order...");

if (order.getIsComplete()) {
int index = getIndexByDishName(aggregatedOrders, order.getDishName());
aggregatedOrders.get(index)
Expand All @@ -99,6 +100,7 @@ private int getIndexByDishName(ArrayList<Order> aggregatedOrders, String dishNam
Order order = aggregatedOrders.get(i);
String orderDishName = order.getDishName().trim();
dishName = dishName.trim();

if (orderDishName.equalsIgnoreCase(dishName)) {
return i;
}
Expand All @@ -115,6 +117,7 @@ private int getIndexByDishName(ArrayList<Order> aggregatedOrders, String dishNam
private float calculateTotalCost(ArrayList<Order> orders) {
logger.info("Calculating total cost...");
float totalCost = 0;

for (Order order : orders) {
totalCost += order.getTotalOrderCost();
logger.info("Total cost: " + totalCost);
Expand Down
Loading
Loading