private static void Transact(string cardNumber) { try { var transactionAmount = _vendingMachineInstance.CurrentItemAmount; Console.WriteLine("Card inserted"); var cardToTransact = _vendingMachineInstance.FindCard(cardNumber); Console.Write("Please enter Pin: "); var input = Console.ReadLine(); uint inputPin; if (UInt32.TryParse(input, out inputPin)) { if (cardToTransact.ValidatePin(inputPin)) //Pin is correct { //1.Deduct the amount from users' card. if (!cardToTransact.DebitAmount(transactionAmount)) { throw new InsufficientExecutionStackException("Insufficient funds on your account."); } //2.Credit Vending machine account _vendingMachineInstance.CreditVendingAmount(transactionAmount); //3. Serve the vending item out. var item = _vendingMachineInstance.VendIt(); Console.WriteLine("Your card has been deducted with {0}", transactionAmount); Console.WriteLine("Please collect your {0}.Thank you", item.Name); } } } catch (Exception exception) { Console.WriteLine(exception.Message); Console.WriteLine("Please start again."); } Console.Read(); }