@Override public Set<Ingredient> getAllIngredients() { boolean ingredientIncluded = false; Set<Ingredient> allIngredients = new HashSet<Ingredient>(); allIngredients.clear(); if (fullMenu != null && !fullMenu.isEmpty()) { for (Dish dish : fullMenu) { Set<Ingredient> newIngredients = dish.getIngredients(); if (newIngredients != null && !newIngredients.isEmpty()) { if (allIngredients != null && !allIngredients.isEmpty()) { for (Ingredient newIngredient : newIngredients) { Iterator<Ingredient> iterator = allIngredients.iterator(); ingredientIncluded = false; while (iterator.hasNext() && ingredientIncluded == false) { Ingredient existingIngredient = iterator.next(); if (existingIngredient.getName().equals(newIngredient.getName())) { existingIngredient.setQuantity( existingIngredient.getQuantity() + newIngredient.getQuantity() * numberOfGuests); existingIngredient.setPrice( existingIngredient.getPrice() + newIngredient.getPrice() * numberOfGuests); allIngredients.remove(existingIngredient); allIngredients.add( new Ingredient( existingIngredient.getName(), existingIngredient.getQuantity(), existingIngredient.getUnit(), existingIngredient.getPrice())); ingredientIncluded = true; } } if (ingredientIncluded == false) { allIngredients.add(newIngredient); } } } else { Iterator<Ingredient> iterator = newIngredients.iterator(); while (iterator.hasNext()) { Ingredient newIngredient = iterator.next(); allIngredients.add( new Ingredient( newIngredient.getName(), newIngredient.getQuantity() * numberOfGuests, newIngredient.getUnit(), newIngredient.getPrice() * numberOfGuests)); } } } } return allIngredients; } return null; }
@Override public float getTotalMenuPrice() { /*double counter = 0; Set<Ingredient> priceIngredients = getAllIngredients(); if(priceIngredients != null && !priceIngredients.isEmpty()) { Iterator<Ingredient> iterator = priceIngredients.iterator(); while (iterator.hasNext()) { Ingredient ingredient = iterator.next(); counter = counter + ingredient.getPrice(); System.out.println(counter); } float totalPrice = (float) counter; return totalPrice; } return 0;*/ double totalPrice = 0.0; if (fullMenu != null) { for (Dish menus : fullMenu) { Set<Ingredient> ingredients = menus.getIngredients(); for (Ingredient ingredient : ingredients) { totalPrice += ingredient.getPrice(); } } } return (float) totalPrice; }
public double getIndividualItemCost(Dish dish) { double price = 0.0; if (dish != null) { Set<Ingredient> ingredients = dish.getIngredients(); for (Ingredient ingredient : ingredients) { price += ingredient.getPrice(); } } return price; }
public double getPrice() { return price + ingredient.getPrice(); }