/* * Bryan * Fitness Menu */ using System; using System.Collections.Generic; namespace bryan_FitnessMenu { public class Order { public List<Drink> Drinks { get; set; } = new List<Drink>(); public double TotalPrice { get; set; } = 0.00; public int NumberOfDrinks { get { return this.Drinks.Count; } } public string OrderNumber = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 8); /// <summary> /// Overrides the ToString and returns a receipt for the order /// </summary> /// <returns></returns> public override string ToString() { if (this.Drinks.Count <= 0) return ""; string formatted = $"Order #: {OrderNumber}{Environment.NewLine}Number of Drinks: {this.NumberOfDrinks}{Environment.NewLine}---{Environment.NewLine}"; // Add all the drinks foreach (Drink _drink in this.Drinks) formatted += _drink.ToString(); // Update our price CalculatePrice(); formatted += $"Order Total: {this.TotalPrice:c}"; return formatted; } /// <summary> /// Updates the total price for this order. /// </summary> public void CalculatePrice() { // Reset the price this.TotalPrice = 0.00; // Don't process if we don't have any drinks if (this.Drinks.Count == 0) return; foreach (Drink _drink in this.Drinks) this.TotalPrice += _drink.Price; } } }