/// <summary>
        /// Übernahme des Einwurfs in das Münzdepot.
        /// Rückgabe des Retourgeldes aus der Kasse. Staffelung des Retourgeldes
        /// hängt vom Inhalt der Kasse ab.
        /// </summary>
        /// <param name="coins">Aktueller Zustand des Münzdepots</param>
        public IEnumerable <Coin> FinishPayment(IEnumerable <Coin> coins)
        {
            int retCents = ReturnCents;

            Coin[] coinsArray = coins
                                .OrderByDescending(c => c.CoinValue)
                                .ToArray();

            if (retCents > 0)
            {
                for (int i = 0; i < coinsArray.Length; i++)
                {
                    while (coinsArray[i].Amount > 0 && retCents - coinsArray[i].CoinValue >= 0)
                    {
                        ReturnCoinValues = $"{ReturnCoinValues}{coinsArray[i].CoinValue};";
                        retCents        -= coinsArray[i].CoinValue;
                        coinsArray[i].Amount--;
                    }
                }
            }

            if (ReturnCoinValues.Length > 0)
            {
                ReturnCoinValues = ReturnCoinValues.Remove(ReturnCoinValues.Length - 1);
            }

            DonationCents = retCents;

            return(coinsArray.OrderBy(c => c.CoinValue));
        }
        /// <summary>
        /// Münze wird eingenommen.
        /// </summary>
        /// <param name="coinValue"></param>
        /// <returns>isFinished ist true, wenn der Produktpreis zumindest erreicht wurde</returns>
        public bool InsertCoin(int coinValue)
        {
            int productPrice = Product.PriceInCents;

            ThrownInCents += coinValue;
            ReturnCents    = ThrownInCents - productPrice;
            int sum = ReturnCents;

            while (sum > 0)
            {
                if (sum - 200 >= 0)
                {
                    sum -= 200;
                    ReturnCoinValues += "200;";
                }
                else if (sum - 100 >= 0)
                {
                    sum -= 100;
                    ReturnCoinValues += "100;";
                }
                else if (sum - 50 >= 0)
                {
                    sum -= 50;
                    ReturnCoinValues += "50;";
                }
                else if (sum - 20 >= 0)
                {
                    sum -= 20;
                    ReturnCoinValues += "20;";
                }
                else if (sum - 10 >= 0)
                {
                    sum -= 10;
                    ReturnCoinValues += "10;";
                }
                else if (sum - 5 >= 0)
                {
                    sum -= 5;
                    ReturnCoinValues += "5;";
                }
                else if (sum - 2 >= 0)
                {
                    sum -= 2;
                    ReturnCoinValues += "2;";
                }
                else if (sum - 1 >= 0)
                {
                    sum -= 1;
                    ReturnCoinValues += "1;";
                }
            }
            ReturnCoinValues = ReturnCoinValues.Remove(ReturnCoinValues.Length - 1, 1);

            return(coinValue >= Product.PriceInCents);
        }
Пример #3
0
        /// <summary>
        /// Übernahme des Einwurfs in das Münzdepot.
        /// Rückgabe des Retourgeldes aus der Kasse. Staffelung des Retourgeldes
        /// hängt vom Inhalt der Kasse ab.
        /// </summary>
        /// <param name="coins">Aktueller Zustand des Münzdepots</param>
        public void FinishPayment(IEnumerable <Coin> coins)
        {
            int ret = _returnCents;

            if (ret == 0)
            {
                ReturnCoinValues = "0";
            }
            foreach (var item in coins.OrderByDescending(c => c.CoinValue))
            {
                while (ret >= item.CoinValue && item.Amount > 0 && ret > 0)
                {
                    ret -= item.CoinValue;
                    item.Amount--;
                    ReturnCoinValues = $"{ReturnCoinValues}{item.CoinValue};";
                }
            }
            if (ReturnCoinValues.Length > 1)
            {
                ReturnCoinValues = ReturnCoinValues.Remove(ReturnCoinValues.Length - 1);
            }
            _donationCents = ret;
        }