Skip to content

Commit

Permalink
Merge pull request #318 from DextheChik3n/316-add-dish-print-bug-v2.1
Browse files Browse the repository at this point in the history
Resolve add dish print bug
  • Loading branch information
ShaniceTang authored Nov 11, 2023
2 parents 181a257 + 7c85175 commit aa9f0d8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
10 changes: 1 addition & 9 deletions src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import seedu.cafectrl.CafeCtrl;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;
import seedu.cafectrl.ui.ErrorMessages;
import seedu.cafectrl.ui.Ui;

Expand Down Expand Up @@ -35,14 +34,7 @@ public void execute() {
logger.info("Executing ListIngredientCommand...");
try {
Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
ui.showIngredientsHeader(selectedDish);

for (Ingredient ingredient : selectedDish.getIngredients()) {
ui.formatListIngredient(ingredient.getName(),
ingredient.getQty()+ingredient.getUnit());
}

ui.showIngredientsEndCap();
ui.showListIngredientsMessage(selectedDish);
} catch (IndexOutOfBoundsException e) {
logger.log(Level.WARNING, "ListIngredientCommand unsuccessful: " + e.getMessage(), e);
throw new IllegalArgumentException(ErrorMessages.UNLISTED_DISH);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/cafectrl/data/dish/Dish.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public ArrayList<Ingredient> getIngredients() {
public float getPrice() {
return price;
}
public String getPriceString() {
return this.dollarValue.format(this.price);
}

public void setPrice(float newPrice) {
this.price = newPrice;
Expand Down
57 changes: 37 additions & 20 deletions src/main/java/seedu/cafectrl/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import seedu.cafectrl.command.ListSaleByDayCommand;
import seedu.cafectrl.command.ViewTotalStockCommand;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;

public class Ui {
Expand Down Expand Up @@ -46,39 +47,55 @@ public void showGoodbye() {
showToUser(Messages.GOODBYE_MESSAGE);
}

//@@author NaychiMin
/**
* Prints out the quantity of each ingredient needed for the
* dish that the user selects.
* dish in a table format.
*
* @param selectedDish Dish for ingredients to be listed out.
* @param dish Dish for ingredients to be listed out.
*/
public void showIngredientsHeader(Dish selectedDish) {
String ingredientsString = String.format("|%-55s|", " Dish: " + selectedDish.getName());
showToUser(Messages.INGREDIENTS_END_CAP);
showToUser(ingredientsString);
showToUser(Messages.INGREDIENTS_CORNER);
showToUser(Messages.INGREDIENTS_TITLE);
showToUser(Messages.INGREDIENTS_CORNER);
public void showListIngredientsMessage(Dish dish) {
showDishNameHeader(dish);
showIngredientList(dish);
showIngredientsEndCap();
}

public void showDishNameHeader(Dish dish) {
String dishNameString = String.format("|%-55s|", " Dish: " + dish.getName());
showToUser(Messages.INGREDIENTS_END_CAP,
dishNameString,
Messages.INGREDIENTS_CORNER);
}

public void showIngredientList(Dish dish) {
showToUser(Messages.INGREDIENTS_TITLE,
Messages.INGREDIENTS_CORNER);

ArrayList<Ingredient> ingredients = dish.getIngredients();
for (Ingredient ingredient : ingredients) {
formatListIngredient(ingredient.getName(), ingredient.getQty() + ingredient.getUnit());
}
}

public void showIngredientsEndCap() {
showToUser(Messages.INGREDIENTS_END_CAP);
}


//@@author DextheChik3n
public void printAddDishMessage(Dish dish) {
String dishNameString = "Dish Name: " + dish.getName();
DecimalFormat dollarValue = new DecimalFormat("0.00");
float dishPrice = dish.getPrice();
String dishPriceString = "Dish Price: $" + dollarValue.format(dishPrice);

showToUser(Messages.ADD_DISH_MESSAGE,
dishNameString,
dishPriceString);
showToUser(Messages.ADD_DISH_MESSAGE + "\n");
showDishNameHeader(dish);
showDishPrice(dish);
showIngredientList(dish);
showIngredientsEndCap();
}

showIngredientsHeader(dish);
public void showDishPrice(Dish dish) {
String dishPriceString = String.format("|%-55s|", " Price: $" + dish.getPriceString());
showToUser(dishPriceString, Messages.INGREDIENTS_CORNER);
}

//@@author
/**
* Shows delete message to user
*
Expand Down

0 comments on commit aa9f0d8

Please sign in to comment.