示例#1
0
        private static void RunChangeCalculator()
        {
            _changeCalculator = new Infrastructure.Instances.ChangeCalculator();

            while (true)
            {
                var itemCostResult = GetInputValue("item cost");

                if (itemCostResult.exit)
                {
                    return;
                }

                var amountGivenResult = GetInputValue("amount given");

                if (amountGivenResult.exit)
                {
                    return;
                }

                var change = _changeCalculator.CalculateChange
                                 (amountGivenResult.value, itemCostResult.value);
                if (change < 0)
                {
                    continue;
                }
                _changeCalculator.GiveChange(change);
                break;
            }
        }
示例#2
0
 public IActionResult Index(int?pay, int?amount)
 {
     if (pay.HasValue && amount.HasValue)
     {
         var result = changeCalculator.CalculateChange(pay.Value, amount.Value);
         ViewData["pay"]    = pay.Value;
         ViewData["amount"] = amount.Value;
         return(View(result));
     }
     else
     {
         return(View());
     }
 }
示例#3
0
        private PurchaseResult ProcessPurchase(double[] coinsEntered)
        {
            if (SelectedProduct != null)
            {
                var change = _changeCalculator.CalculateChange(
                    new Transaction
                {
                    Product      = SelectedProduct,
                    CoinsEntered = coinsEntered
                });

                var result = new PurchaseResult
                {
                    Accepted  = change >= 0,
                    AmountDue = change
                };

                return(result);
            }

            return(null);
        }
示例#4
0
        public ChangeModel Calculate(int pay, int amount)
        {
            var result = changeCalculator.CalculateChange(pay, amount);

            return(result);
        }