// member methods public void RunSimulation() { // Choose card or coin string paymentMethod = UserInterface.ChoosePaymentMethod(); string userSelection = "0"; if (paymentMethod == "1") { Console.Clear(); //display available funds customer.InsertPayment(customer.wallet.card); //pick soda userSelection = UserInterface.MakeSelection(sodaMachine, paymentMethod); //check funds are available bool canCompleteTransaction = sodaMachine.ProcessTransaction(userSelection, customer); if (canCompleteTransaction) { double sodaCost = Math.Round(SodaMachine.GetSodaCost(userSelection), 2); sodaMachine.CompleteTransaction(customer, sodaCost, userSelection); } else // Funds not available { sodaMachine.CancelTransaction(); } } else { //User can enter more money while (userSelection == "0") { //Insert coin into hopper customer.InsertPayment(sodaMachine); double moneyInHopper = Math.Round(Verification.CountMoney(sodaMachine.hopperIn), 2); // Count money in hopper Console.Clear(); Console.WriteLine($"Money inserted: {moneyInHopper:C2}\n"); // Display money in hopper //Choose soda OR enter more money userSelection = UserInterface.MakeSelection(sodaMachine, paymentMethod); } // Break once user chooses soda bool canCompleteTransaction = sodaMachine.ProcessTransaction(userSelection); if (canCompleteTransaction) // If adequate amount of money passed in { sodaMachine.CompleteTransaction(customer, userSelection); } else // If inadequate amount of money passed in { sodaMachine.CancelTransaction(customer); } } }
//methods public void RunSimulation() { while (sodaMachine.inventory.Count > 0) { customer.DisplayCurrentStatus(); sodaMachine.DisplayInventory(); int choice = customer.SelectSoda(); bool isInInventory = sodaMachine.CheckInventory(choice); Coin coin; if (isInInventory == true) { do { double value = sodaMachine.GetTemporaryRegister(); coin = customer.InputCoins(value); if (coin != null) { sodaMachine.AddToTemporaryRegister(coin); } } while (coin != null); Can can = sodaMachine.CompleteTransaction(choice); if (can != null) { customer.AddToBackpack(can); } List <Coin> change = sodaMachine.ReturnMoney(); customer.AddChangeToWallet(change); sodaMachine.ClearTemporaryRegister(); } } }