public void AddCoins(Coins coins) { switch (coins.CoinType) { case CoinType.One: Coins.MoveCoins(coins, CoinsInBox.CoinsOne); break; case CoinType.Two: Coins.MoveCoins(coins, CoinsInBox.CoinsTwo); break; case CoinType.Five: Coins.MoveCoins(coins, CoinsInBox.CoinsFive); break; case CoinType.Ten: Coins.MoveCoins(coins, CoinsInBox.CoinsTen); break; } }
private void InsertCoin(Coins clientCoins, ProgressBar progressBar, Label coinStateLabel) { if (clientCoins.Amount != 0) { progressBar.Value--; clientCoins.Remove(1); _coffeMachine.CoinBox.AddCoin(clientCoins.CoinType); labelCoinsInserted.Text = _coffeMachine.CoinBox.GetSumm() + " рублей"; coinStateLabel.Text = clientCoins.Amount + " монеты"; } }
public static void MoveCoins(Coins coinsFrom, Coins coinsTo) { var transferAmoun = coinsFrom.Amount; coinsTo.Add(transferAmoun); coinsFrom.Remove(transferAmoun); }
public HandfulOfCoins(int coinsOne, int coinsTwo, int coinsFive, int coinsTen) { CoinsOne = new Coins(CoinType.One, coinsOne); CoinsTwo = new Coins(CoinType.Two, coinsTwo); CoinsFive = new Coins(CoinType.Five, coinsFive); CoinsTen = new Coins(CoinType.Ten, coinsTen); }
/// <summary> /// Расчет сдачи по монетам каждого достоинства с проверкой их наличия /// </summary> /// <param name="summToBack"></param> /// <param name="coinsInMachine"></param> /// <returns></returns> private int GetChangeForCoins(ref int summToBack, Coins coinsInMachine) { var coinsToBack = summToBack / (int)coinsInMachine.CoinType; if (coinsToBack > 0 && coinsInMachine.Amount > 0) { var coinsToChange = coinsInMachine.Remove(coinsToBack); summToBack -= coinsToChange*(int) coinsInMachine.CoinType; return coinsToChange; } return 0; }