Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            SodaMachine machine = new SodaMachine();
            //purpose?
            // handle bad user input, ensuring that any user input is validated and reobtained if necessary


            //What do you need for the method?


            //Method What can it do?
        }
Ejemplo n.º 2
0
        //Customer chooses a soda
        public static string MakeSelection(SodaMachine sodaMachine, string paymentMethod)
        {
            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 prompt interface to enter more coins
                {
                    return(verifiedUserInput);
                }
            }
            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 their 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);
        }
Ejemplo n.º 3
0
        // 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);
                }
            }
        }
Ejemplo n.º 4
0
 //constructor
 public Simulation()
 {
     sodaMachine = new SodaMachine();
     customer    = new Customer();
 }
Ejemplo n.º 5
0
 public Simulation()
 {
     sodaMachine       = new SodaMachine();
     customer          = new Customer();
     temporaryRegister = new List <Coin>();
 }
Ejemplo n.º 6
0
        //Insert user payment
        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);
        }