Ejemplo n.º 1
0
        public ChangeResponse CoinReturn(ChangeRequest transaction)
        {
            var coinCount = new Change();

            coinCount.SilverDollars = transaction.ChangeOwed/100;
            coinCount.Quarters = (transaction.ChangeOwed - coinCount.SilverDollars*100)/25;
            coinCount.Dimes = (transaction.ChangeOwed - (coinCount.SilverDollars*100 + coinCount.Quarters*25))/10;
            coinCount.Nickels = (transaction.ChangeOwed - (coinCount.SilverDollars*100 + coinCount.Quarters*25 + coinCount.Dimes*10))/5;
            coinCount.Pennies = (transaction.ChangeOwed -
                                (coinCount.SilverDollars*100 + coinCount.Quarters*25 + coinCount.Dimes*10 +
                                 coinCount.Nickels*5));

            var changeResponse = new ChangeResponse();
            changeResponse.Coins = coinCount;
            changeResponse.Item = transaction.Item;
            changeResponse.ChangeOwed = transaction.ChangeOwed;
            changeResponse.Payment = transaction.Payment;
            return changeResponse;
        }
Ejemplo n.º 2
0
 public ChangeResponse MakeChange(ChangeRequest transaction)
 {
     var changeResponse = CoinReturn(transaction);
     return changeResponse;
 }
Ejemplo n.º 3
0
        private ChangeRequest GetMoney(VendingItem item)
        {
            var itemTransaction = new ChangeRequest();
               itemTransaction.Item = item;
               bool result;
               decimal userPayment;
               bool isEnough=false;

            Console.WriteLine("Your Selection:{0} costs:{1:c}",item.Name, item.Price);

               do
               {
               Console.Write("How much money are you putting into the vending machine?:");
               string userInput = Console.ReadLine();

               result = decimal.TryParse(userInput, out userPayment);
               if (result==false)
               {
                   Console.WriteLine("You entered {0}, you must enter your payment as a number", userInput);
               }

               else if (userPayment<item.Price)
               {
                   Console.WriteLine("Your payment must be more than the price of the item! You entered {0} but {1} costs {2:c}. ", userPayment, item.Name, item.Price);
               }
               else
               {
                   isEnough = true;
               }
               } while (result==false || isEnough==false); //weird. if i flip order result/isenough it doesn't like it.
               itemTransaction.Payment = (int)(userPayment*100);
               itemTransaction.ChangeOwed = (int)(itemTransaction.Payment - itemTransaction.Item.Price*100);
               return itemTransaction;
        }