public void InsertCoin(InsertableCoinWeights coinWeight, InsertableCoinSizes coinSize) { InsertedCoin newCoin = this.CoinAcceptor.InsertCoin(coinWeight, coinSize); // Rejected coins should go to return. Otherwise, add them to current amount inserted. if (newCoin == InsertedCoin.Rejected) { this.AddToCoinReturn(newCoin); } else { this.CurrentAmountInserted += this.CoinAppraiser.GetCoinValue(newCoin); if (this.InternalSafe.ContainsKey(newCoin)) { this.InternalSafe[newCoin]++; } else { this.InternalSafe.Add(newCoin, 1); } } // Update display if (this.CurrentAmountInserted == 0) { this.Display.Message = VendingMachine.InsertCoinsMessage; } else { this.Display.Message = string.Format(VendingMachine.CurrentAmountMessageFormat, this.CurrentAmountInserted); } }
public InsertedCoin InsertCoin(InsertableCoinWeights weightOfCoin, InsertableCoinSizes sizeOfCoin) { if ((weightOfCoin == InsertableCoinWeights.WeightOfNickel) && (sizeOfCoin == InsertableCoinSizes.SizeOfNickel)) { return InsertedCoin.Nickel; } if ((weightOfCoin == InsertableCoinWeights.WeightOfDime) && (sizeOfCoin == InsertableCoinSizes.SizeOfDime)) { return InsertedCoin.Dime; } if ((weightOfCoin == InsertableCoinWeights.WeightOfQuarter) && (sizeOfCoin == InsertableCoinSizes.SizeOfQuarter)) { return InsertedCoin.Quarter; } return InsertedCoin.Rejected; }