public static string MakeSelection(SodaMachine sodaMachine, string paymentMethod) // Customer chooses soda
        {
            Console.WriteLine("Please make a selection: \n");
            sodaMachine.DisplayCurrentInventory();
            string userInput;
            string verifiedUserInput;

            if (paymentMethod == "1") // Display if card payment
            {
                Console.Write("Select a soda: ");
                userInput         = Console.ReadLine();
                verifiedUserInput = Verification.VerifyUserInput(userInput, 1, 3); // Only allow customer to choose a soda
            }
            else // Display if coin payment
            {
                Console.Write("\nSelect a soda, or enter 0 to insert more coins: ");
                userInput         = Console.ReadLine();
                verifiedUserInput = Verification.VerifyUserInput(userInput, 0, 3); // Allow customer to choose to input more coins
                if (verifiedUserInput == "0")                                      // Return to interface to enter more coins
                {
                    return(verifiedUserInput);
                }
            }
            // Move this to Verification?
            bool canExists = false;

            while (!canExists)
            {
                switch (verifiedUserInput)
                {
                case "1":
                    canExists = Verification.CheckIfObjectExists(sodaMachine.inventory, "Cola");
                    break;

                case "2":
                    canExists = Verification.CheckIfObjectExists(sodaMachine.inventory, "Orange Soda");
                    break;

                case "3":
                    canExists = Verification.CheckIfObjectExists(sodaMachine.inventory, "Root Beer");
                    break;
                }
                if (!canExists) // Prompt to make another choice if soda is sold out
                {
                    Console.WriteLine("This soda is sold out. Please make another selection.");
                    userInput         = Console.ReadLine();
                    verifiedUserInput = Verification.VerifyUserInput(userInput, 1, 3);
                }
            }
            return(verifiedUserInput);
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
        public void InsertPayment(SodaMachine sodaMachine)
        {
            DisplayContents(wallet);
            Console.WriteLine("\nType 1 to insert quarter\nType 2 to insert dime\nType 3 to insert nickel\nType 4 to insert penny");
            string userInput         = Console.ReadLine();
            string verifiedUserInput = Verification.VerifyUserInput(userInput, 1, 4);
            Coin   insertedCoin      = null;

            while (insertedCoin == null)
            {
                switch (verifiedUserInput)
                {
                case "1":
                    bool coinExists = Verification.CheckIfObjectExists(wallet.coins, "Quarter");
                    if (coinExists)
                    {
                        for (int i = 0; i < wallet.coins.Count; i++)
                        {
                            if (wallet.coins[i].name == "Quarter")
                            {
                                insertedCoin = wallet.coins[i];
                                wallet.coins.RemoveAt(i);
                                break;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("You do not have any quarters to insert. Choose another coin.");
                        userInput         = Console.ReadLine();
                        verifiedUserInput = Verification.VerifyUserInput(userInput, 1, 4);
                        break;
                    }
                    break;

                case "2":
                    coinExists = Verification.CheckIfObjectExists(wallet.coins, "Dime");
                    if (coinExists)
                    {
                        for (int i = 0; i < wallet.coins.Count; i++)
                        {
                            if (wallet.coins[i].name == "Dime")
                            {
                                insertedCoin = wallet.coins[i];
                                wallet.coins.RemoveAt(i);
                                break;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("You do not have any dimes to insert. Choose another coin.");
                        userInput         = Console.ReadLine();
                        verifiedUserInput = Verification.VerifyUserInput(userInput, 1, 4);
                        break;
                    }
                    break;

                case "3":
                    coinExists = Verification.CheckIfObjectExists(wallet.coins, "Nickel");
                    if (coinExists)
                    {
                        for (int i = 0; i < wallet.coins.Count; i++)
                        {
                            if (wallet.coins[i].name == "Nickel")
                            {
                                insertedCoin = wallet.coins[i];
                                wallet.coins.RemoveAt(i);
                                break;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("You do not have any nickels to insert. Choose another coin.");
                        userInput         = Console.ReadLine();
                        verifiedUserInput = Verification.VerifyUserInput(userInput, 1, 4);
                        break;
                    }
                    break;

                case "4":
                    coinExists = Verification.CheckIfObjectExists(wallet.coins, "Penny");
                    if (coinExists)
                    {
                        for (int i = 0; i < wallet.coins.Count; i++)
                        {
                            if (wallet.coins[i].name == "Penny")
                            {
                                insertedCoin = wallet.coins[i];
                                wallet.coins.RemoveAt(i);
                                break;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("You do not have any pennies to insert. Choose another coin.");
                        userInput         = Console.ReadLine();
                        verifiedUserInput = Verification.VerifyUserInput(userInput, 1, 4);
                        break;
                    }
                    break;
                }
            }
            sodaMachine.hopperIn.Add(insertedCoin);
        }
Beispiel #4
0
        // constructor (SPAWN)

        public Simulation()
        {
            sodaMachine = new SodaMachine();
            customer    = new Customer();
        }