Exemplo n.º 1
0
        // member methods (CAN DO)

        public void RunSimulation()
        {
            string paymentMethod = UserInterface.ChoosePaymentMethod(); // Choose card or coin payment
            string userSelection = "0";

            if (paymentMethod == "1") // Card payment
            {
                Console.Clear();
                customer.InsertPayment(customer.wallet.card);                                          // Display available funds
                userSelection = UserInterface.MakeSelection(sodaMachine, paymentMethod);               // Choose soda
                bool canCompleteTransaction = sodaMachine.ProcessTransaction(userSelection, customer); // Verify adequate funds are available
                if (canCompleteTransaction)                                                            // If funds available
                {
                    // Clean this up - redundant call of GetSodaCost()
                    double sodaCost = Math.Round(SodaMachine.GetSodaCost(userSelection), 2);
                    sodaMachine.CompleteTransaction(customer, sodaCost, userSelection);
                }
                else // Funds not available
                {
                    sodaMachine.CancelTransaction();
                }
            }
            else
            {
                while (userSelection == "0")                                                             // User opts to enter more money
                {
                    customer.InsertPayment(sodaMachine);                                                 // Insert coin into machine, stored in hopperIn
                    double moneyInHopper = Math.Round(Verification.CountMoney(sodaMachine.hopperIn), 2); // Calculate money currently in hopper
                    Console.Clear();
                    Console.WriteLine($"Money inserted: {moneyInHopper:C2}\n");                          // Display money in hopper
                    userSelection = UserInterface.MakeSelection(sodaMachine, paymentMethod);             // Choose soda or enter more money
                } // Break once user chooses soda
                bool canCompleteTransaction = sodaMachine.ProcessTransaction(userSelection);             // Calculate money inserted v cost of soda
                if (canCompleteTransaction)                                                              // If adequate amount of money passed in
                {
                    sodaMachine.CompleteTransaction(customer, userSelection);
                }
                else // If inadequate amount of money passed in
                {
                    sodaMachine.CancelTransaction(customer);
                }
            }
        }