/// <summary> /// Occurs when product selection is changed /// </summary> private void OnProductSelected(object sender, ProductForSale selected) { // If enough money has been inserted for the selected product, dispense it and thank user if (this.ProductSelectorButtons.CanSelectedProductBePurchased(this.CurrentAmountInserted)) { // Dispense, and thank user this.Display.Message = VendingMachine.ThankYouMessage; // Subscribe so that on next read, we can reset our current amount inserted and display the // INSERT COINS message this.Display.OnNextRead += this.OnDisplayReadAfterProductDispensed; // Any remaining change should go to coin return this.DispenseChange(); } else { this.Display.Message = string.Format(VendingMachine.PriceMessageFormat, this.ProductSelectorButtons.GetProductPrice(selected)); // Subscribe so that on next read, we can display the PRICE and display the // INSERT COINS message or current amount inserted this.Display.OnNextRead += this.OnDisplayReadAfterProductNotDispensed; } }
public decimal GetProductPrice(ProductForSale product) { return (decimal)(((decimal)product) / (decimal)100); }