Exemple #1
0
        public void AddCoin(ICoin coin)
        {
            if (coin.IsValidCoin())
            {
                switch (coin.Amount)
                {
                case 0.01M:
                    coin.Volume = 0.00845350563972975M;
                    break;

                case 0.05M:
                    coin.Volume = 0.169070112794595M;
                    break;

                case 0.10M:
                    coin.Volume = 0.07669020316362829M;
                    break;

                case 0.25M:
                    coin.Volume = 0.19172550790907072M;
                    break;

                case 0.50M:
                    coin.Volume = 0.38345101581814145M;
                    break;

                case 1:
                    coin.Volume = 0.2738935827272439M;
                    break;
                }
                if (_coins.Sum(x => x.Volume) + coin.Volume <= 42)
                {
                    _coins.Add(coin);
                }
                else
                {
                    throw new InvalidOperationException($"Coinjar is full. Cannot add coin: {coin.Amount}USD");
                }
            }
            else
            {
                throw new InvalidOperationException($"Invalid coin: {coin.Amount}USD");
            }
        }