Skip to content

Commit

Permalink
Merge pull request #390 from Cazh1/Update-Code-Quality-
Browse files Browse the repository at this point in the history
Update code quality
  • Loading branch information
ziyi105 authored Nov 13, 2023
2 parents 16ff7a4 + ba4f595 commit ad1f273
Show file tree
Hide file tree
Showing 27 changed files with 85 additions and 61 deletions.
2 changes: 1 addition & 1 deletion docs/AboutUs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Display | Name | Github Profile | Portfolio
![](images/aboutUs/naychimin.png) | 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)
<img height="100" src="images/aboutUs/dexter.jpg" width="100"/> | Dexter Hoon | [Github](https://github.com/DextheChik3n) | [Portfolio](team/dexthechik3n.md)
![](https://via.placeholder.com/100.png?text=Photo) | Chua Zhong Heng | [Github](https://github.com/Cazh1/tp) | [Portfolio](team/cazh1.md)
![](images/aboutUs/zhongheng.jpg) | Chua Zhong Heng | [Github](https://github.com/Cazh1/tp) | [Portfolio](team/cazh1.md)
16 changes: 10 additions & 6 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,21 @@ When the `execute()` method of AddOrderCommand is invoked in Main, the parsed `o

A `Chef` object is then created to process the order by running `cookDish()`.
This method first checks if the order has already been completed by running `order.getIsCompleted()`.
If the order has not been completed, the `showDeleteMesage()` in the Ui component is triggered to display a message to show the user that the dish is being 'prepared'.
If the order has not been completed, the `showChefMesage()` in the Ui component is triggered to display a message to show the user that the dish is being 'prepared'.
An ArrayList of Ingredients, ingredientList, is retrieved from the `order` object by `order.getIngredientList()`.
This ingredientList is passed into the `pantry` object in `pantry.decreaseIngredientsStock()` to process the ingredients used from the pantry stock.
The order is then marked as completed by `order.setComplete()`
This ingredientList is passed into the `pantry` object in `pantry.isDishCook()` to process the ingredients used from the pantry stock.
This method returns a boolean, true if there is sufficient ingredients in the pantry, false is insufficient.
The order completeness status is updated by the boolean method, passing it into `order.setComplete()`

Returning to the AddOrderCommand, the `order` object is checked to be completed again by running `order.getIsCompleted()`.
This verifies that the ingredientList has been successfully retrieved and passed into `pantry.decreaseIngredientsStock()` to run without errors.
This verifies that the has been successfully completed.
After verifying that the order has been completed, the cost of the order is added to the total order by `orderList.addCost()`.
The total cost is the shown to the user using `ui.showOrderStatus`.
Lastly, the pantry checks on the remaining ingredients in stock and calculates the potential future dishes able to be made with the remaining stock, using `pantry.calculateDishAvailability()`.

The total sum of orders in the `orderList` object is retrieved using `orderList.getTotalCost()`.
This is then passed into Ui using `ui.showTotalCost()` to display a message to the user with the total order cost.
If the order has been marked incomplete, the details of the orderedDish is retrieved from `Order` using `order.getOrderedDish()`.
This is then passed on to the `Pantry` to figure out the missing ingredients, by `pantry.calculateMaxDishes()`.
Lastly, the user is shown a message informing that the order has not been completed due to the lack of ingredients using `ui.showIncompleteOrder()`.

### Next Day
A `next_day` command can be used advance the current day.
Expand Down
44 changes: 25 additions & 19 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ Format: `list_menu`

Example:
```
+-----------------------------------------+
| Ah, behold, the grand menu of delights! |
+--------------------------+--------------+
| Dish Name | Price |
+--------------------------+--------------+
| 1. chicken rice | $2.50 |
| 2. chicken curry | $4.30 |
+-----------------------------------------+
+-------------------------------------------------------+
| Ah, behold, the grand menu of delights! |
+----------------------------------------+--------------+
| Dish Name | Price |
+----------------------------------------+--------------+
| 1. chicken rice | $2.50 |
| 2. chicken curry | $4.30 |
+-------------------------------------------------------+
```

<!---@@author NaychiMin--->
Expand Down Expand Up @@ -286,6 +286,8 @@ Adds an order consisting of dishes off the menu to an order list

Format: `add_order name/DISH_NAME qty/DISH_QTY`

* The `DISH_QTY` must be a positive integer number.

Example:
```
> add_order name/chicken rice qty/2
Expand All @@ -301,22 +303,23 @@ Available Dishes: 8
Dish: chicken curry
Available Dishes: 4
```
* The `DISH_QTY` must be a positive integer number.

Adds an order to the current business day

Format: `add_order name/DISH_NAME qty/QUANTITY`
However, if there is insufficient ingredients in the pantry required for the desired dish quantity,
the following message will be shown, prompting the user to `buy_ingredient`

Example: `add_order name/chicken rice qty/2`

Output:
```
```agsl
> add_order name/chicken rice qty/2
I'm busy crafting your selected dish in the virtual kitchen of your dreams. Bon appétit!
Is order completed?: true
Total orderList cost: $4.00
+----------------------------------------+--------------+--------------+
| Restock | Current | Needed |
+----------------------------------------+--------------+--------------+
| chicken | 0g | 200g |
+----------------------------------------------------------------------+
| rice | 0g | 100g |
+----------------------------------------------------------------------+
Please restock ingredients before preparing the order :)
```


### Showing total sales : `list_total_sales`
Displays the dishes sold and total sales for each from Day 1 to the current day that
the cafe is operating on.
Expand Down Expand Up @@ -361,6 +364,8 @@ Example: `list_sale day/2`

Output:
- list_sale day/2 lists the dishes sold along with the total sales for day 2.


```
+---------------------------------------------------------------------------+
| Day 2: |
Expand All @@ -374,6 +379,7 @@ Output:
| Total for day: | $12.00 |
+---------------------------------------------------------------------------+
```

### Advancing to the next day: `next_day`

Proceeds to the next business day
Expand Down
20 changes: 17 additions & 3 deletions docs/diagrams/sequence/AddOrderCommand_execute.puml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,24 @@ autonumber
activate ":Pantry"
return
return
opt order.getIsComplete()
destroy ":Chef"
alt order.getIsComplete()
":AddOrderCommand" -> ":OrderList" : addCost(order : Order)
activate ":OrderList"
return
activate ":OrderList"
return
":AddOrderCommand" -> ":Ui" : showOrderStatus(totalCost : String)
activate ":Ui"
return
else
":AddOrderCommand" -> ":Order" : getOrderedDish()
activate ":Order"
return orderedDish : Dish
":AddOrderCommand" -> ":Pantry" : calculateMaxDishes(orderedDish : Dish, menu : Menu, order : Order)
activate ":Pantry"
return
":AddOrderCommand" -> ":Ui" : showIncompleteOrder()
activate ":Ui"
return
end
return
@enduml
Binary file added docs/images/aboutUs/zhongheng.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/class/AddOrderCommandClass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/class/ListMenuCommandClass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/class/NextDayCommandClass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/class/PreviousDayCommandClass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/sequence/AddDishCommand_execute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/sequence/AddOrderCommand_execute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/sequence/ListMenuCommand_execute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/sequence/NextDayCommand_execute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/sequence/PreviousDayCommand_execute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main/java/seedu/cafectrl/CafeCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CafeCtrl {
private CafeCtrl() {
initLogger();
this.ui = new Ui();
this.storage = new Storage(this.ui);
this.storage = new Storage(ui);
this.pantry = this.storage.loadPantryStock();
this.menu = this.storage.loadMenu();
this.sales = this.storage.loadOrderList(menu);
Expand Down Expand Up @@ -74,7 +74,7 @@ private void run() {
}
} while (!command.isExit());

this.storage.saveAll(this.menu, this.sales, this.pantry);
storage.saveAll(menu, sales, pantry);
logger.info("CafeCtrl terminated.");
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/seedu/cafectrl/command/AddOrderCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import seedu.cafectrl.data.Chef;

import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;

import java.util.logging.Logger;
Expand Down Expand Up @@ -45,13 +44,13 @@ public void execute() {
if (order.getIsComplete()) {
orderList.addCost(order);
String totalCost = dollarValue.format(order.getTotalOrderCost());
ui.showOrderStatus(Messages.COMPLETE_ORDER, totalCost);
ui.showOrderStatus(totalCost);
pantry.calculateDishAvailability(menu, order);
} else {
//pass in dish only and not entire menu
Dish orderedDish = order.getOrderedDish();
pantry.calculateMaxDishes(orderedDish, menu, order);
ui.showToUser(Messages.INCOMPLETE_ORDER);
ui.showIncompleteOrder();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static seedu.cafectrl.ui.Ui.OFFSET_LIST_INDEX;

//@@author ShaniceTang
/**
* The BuyIngredientCommand class represents a command to buy ingredients and add them to the pantry.
Expand Down Expand Up @@ -73,7 +75,7 @@ private void addIngredient() {
ingredients.set(i, ingredient);
}

for (int i = ingredients.size() - ui.OFFSET_LIST_INDEX; i >= finalIndex; i--) {
for (int i = ingredients.size() - OFFSET_LIST_INDEX; i >= finalIndex; i--) {
Ingredient ingredient = ingredients.get(i);
buildBuyIngredientMessage(ingredient);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/cafectrl/command/ListMenuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.text.DecimalFormat;
import java.util.logging.Logger;

//@@author Cazh1
/**
* Lists all dishes in the menu to the user.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.cafectrl.command;

import seedu.cafectrl.CafeCtrl;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.Sales;
import seedu.cafectrl.ui.ErrorMessages;
import seedu.cafectrl.ui.Ui;
Expand All @@ -19,13 +18,11 @@ public class ListSaleByDayCommand extends Command {
private final int day;
private final Ui ui;
private final Sales sales;
private final Menu menu;

public ListSaleByDayCommand(int day, Ui ui, Sales sales, Menu menu) {
public ListSaleByDayCommand(int day, Ui ui, Sales sales) {
this.day = day;
this.ui = ui;
this.sales = sales;
this.menu = menu;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.cafectrl.command;

import seedu.cafectrl.CafeCtrl;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.Sales;
import seedu.cafectrl.ui.Ui;

Expand All @@ -13,12 +12,10 @@ public class ListTotalSalesCommand extends Command {
private static Logger logger = Logger.getLogger(CafeCtrl.class.getName());
private Sales sales;
private Ui ui;
private Menu menu;

public ListTotalSalesCommand(Sales sales, Ui ui, Menu menu) {
public ListTotalSalesCommand(Sales sales, Ui ui) {
this.sales = sales;
this.ui = ui;
this.menu = menu;
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/cafectrl/command/NextDayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.logging.Logger;

//@@author Cazh1
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.logging.Logger;

//@@author Cazh1
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;
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/seedu/cafectrl/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ public Command parseCommand(Menu menu, String userInput, Ui ui,
return preparePreviousDay(ui, currentDate);

case ListTotalSalesCommand.COMMAND_WORD:
return prepareShowSales(sales, menu, ui, arguments);
return prepareShowSales(sales, ui, arguments);

case ListSaleByDayCommand.COMMAND_WORD:
return prepareShowSalesByDay(arguments, ui, sales, menu);
return prepareShowSalesByDay(arguments, ui, sales);

default:
logger.warning(ErrorMessages.UNKNOWN_COMMAND_MESSAGE);
Expand Down Expand Up @@ -194,7 +194,7 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u
int dishIndexGroup = 1;
int newPriceGroup = 2;
int dishIndex;
float newPrice;
float newDishPrice;

try {
String dishIndexText = matcher.group(dishIndexGroup).trim();
Expand All @@ -218,13 +218,13 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments, Ui u
}

try {
newPrice = parsePriceToFloat(matcher.group(newPriceGroup).trim());
newDishPrice = parsePriceToFloat(matcher.group(newPriceGroup).trim());
} catch (ParserException e) {
logger.log(Level.WARNING, "Invalid price!", e);
return new IncorrectCommand(e.getMessage(), ui);
}

return new EditPriceCommand(dishIndex, newPrice, menu, ui);
return new EditPriceCommand(dishIndex, newDishPrice, menu, ui);
}

//@@author DextheChik3n
Expand Down Expand Up @@ -813,13 +813,12 @@ private static Command prepareNextDay(Ui ui, Sales sales, CurrentDate currentDat
* Prepares a command to display all sales items.
*
* @param sale The Sales object containing sales data.
* @param menu The Menu object representing the cafe's menu.
* @param ui The Ui object for user interface interactions.
* @return A ShowSalesCommand instance for viewing all sales items.
*/
private static Command prepareShowSales(Sales sale, Menu menu, Ui ui, String arguments) {
private static Command prepareShowSales(Sales sale, Ui ui, String arguments) {
if (arguments.isEmpty()) {
return new ListTotalSalesCommand(sale, ui, menu);
return new ListTotalSalesCommand(sale, ui);
} else {
return new IncorrectCommand(ErrorMessages.WRONG_LIST_TOTAL_SALES_FORMAT, ui);
}
Expand All @@ -832,10 +831,9 @@ private static Command prepareShowSales(Sales sale, Menu menu, Ui ui, String arg
* @param arguments The arguments containing the day for which sales are to be displayed.
* @param ui The Ui object for user interface interactions.
* @param sales The Sales object containing sales data.
* @param menu The Menu object representing the cafe's menu.
* @return A ShowSalesByDayCommand instance for viewing sales items on a specific day.
*/
private static Command prepareShowSalesByDay(String arguments, Ui ui, Sales sales, Menu menu) {
private static Command prepareShowSalesByDay(String arguments, Ui ui, Sales sales) {
final Pattern showSaleByDayPattern = Pattern.compile(SHOW_SALE_BY_DAY_ARGUMENT_STRING);
Matcher matcher = showSaleByDayPattern.matcher(arguments.trim());

Expand All @@ -850,7 +848,7 @@ private static Command prepareShowSalesByDay(String arguments, Ui ui, Sales sale
if (day < 0) {
throw new Exception();
}
return new ListSaleByDayCommand(day, ui, sales, menu);
return new ListSaleByDayCommand(day, ui, sales);
} catch (Exception e) {
return new IncorrectCommand(ErrorMessages.INVALID_DAY_FORMAT, ui);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/cafectrl/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private boolean isFileCorrupted(ArrayList<String> encodedStringArrayList) {
}
} catch (Exception e) {
isHashStringTampered = true;
logger.log(Level.INFO, "Tampered Hash string");
return true;
}
return false;
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/cafectrl/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,16 @@ public void showTotalCost(String dollarCost) {
showToUser("Total order cost: $" + dollarCost);
}

public void showOrderStatus(String orderStatus, String totalCost) {
public void showOrderStatus(String totalCost) {
printLine();
showToUser(orderStatus);
showToUser(Messages.COMPLETE_ORDER);
showTotalCost(totalCost);
printLine();
showDishAvailabilityMessage();
}
public void showIncompleteOrder() {
showToUser(Messages.INCOMPLETE_ORDER);
}

public void showDishAvailabilityMessage() {
showToUser(Messages.AVAILABLE_DISHES);
Expand Down
Loading

0 comments on commit ad1f273

Please sign in to comment.