示例#1
0
 public void VendMachineGo(List<VendingItem> items )
 {
     //  var items = new List<VendingItem>();
     items=   DisplayMenu(items);
        var item = new VendingItem();
      item =  SelectItem(items);
       var transaction= GetMoney(item);
        var changeMaker = new ChangeMaker();
      var changeResponse = changeMaker.MakeChange(transaction);
        ChangePrinter(changeResponse);
      //  Console.ReadLine();
 }
示例#2
0
        private List<VendingItem> ItemListFromArray(string[] allLines)
        {
            var items = new List<VendingItem>();
               foreach (var line in allLines.Skip(1))
               {
               string[] columns = line.Split('|');
               var item = new VendingItem();

               item.Name = columns[0];
               item.Price = decimal.Parse(columns[1]);

               items.Add(item);

               }

               return items;
        }
示例#3
0
 public int FindDifference(VendingItem item, int payment)
 {
     return (int)(item.Price - payment)*100;
 }
示例#4
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;
        }