/// <summary> /// Check cost and pizza count constraints, and add a PizzaClass object to the pizzas list /// </summary> /// <param name="newPizza">PizzaClass object to be added to the order</param> /// <returns>string indicating whether the pizza was successfully added or not</returns> public string AddPizza(PizzaClass newPizza) { //check pizza count constraint and if pizza was built successfully if (pizzas.Count < 12 && newPizza.price != 0.0m) { //check price limit constraint if (total + newPizza.price < 500.00m) { //add pizza to pizzas list, add price of pizza to order total, and return string indicating success this.pizzas.Add(newPizza); total += newPizza.price; OrderString = ToString(); return(newPizza.ToString() + "\nhas been added to your order."); } else { //return string indicating failure of price constraint return("New pizza not added to your order, total may not exceed $500.00"); } } else if (pizzas.Count == 12) { //return string indicating failure of pizza count constraint return("No more than 12 pizzas may be added to a single order"); } else { //return string indicating pizza was not built successfully return("Invalid Selection, please try again."); } }
/// <summary> /// Decrements values in inventory corresponing to the selected ingredients /// </summary> public void DecrementInventory(PizzaClass pizza) { for (int i = 0; i < pizza.toppingSelection.Length; i++) { if (pizza.toppingSelection[i] && inventory[i] > 0) { inventory[i]--; } } }
/// <summary> /// Check inventory to ensure we have all the ingredients necessary to make the ordered pizza /// </summary> public bool CheckInventory(PizzaClass pizza) { //iterate thrugh toppingChoices and check inventory values for all used ingredients for (int i = 0; i < pizza.toppingSelection.Length; i++) { if (pizza.toppingSelection[i] && inventory[i] == 0) { //inform user that the order cannot be fulfilled and return false return(false); } } //if the loop completes, return true return(true); }