Esempio n. 1
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);
        }
Esempio n. 2
0
        //GIVE BACK CHANGE
        private bool DispenseChange(double changeDue)
        {
            // Check total change available, make sure change available is greater than change due
            bool canGiveExactChange = false;

            while (Math.Round(changeDue, 2) >= 0.25)
            {
                //Check for quarters
                bool coinExists = Verification.CheckIfObjectExists(register, "Quarter");
                if (coinExists)
                {
                    for (int i = 0; i < register.Count; i++)
                    {
                        //Loop through and remove quarter
                        if (register[i].name == "Quarter")
                        {
                            //Add remove coins to hopper
                            hopperOut.Add(register[i]);
                            register.RemoveAt(i);                        // Remove coin from register
                            changeDue = Math.Round(changeDue - 0.25, 2); // Decrease change due
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            while (Math.Round(changeDue, 2) >= 0.10)
            {
                bool coinExists = Verification.CheckIfObjectExists(register, "Dime");
                if (coinExists)
                {
                    for (int i = 0; i < register.Count; i++)
                    {
                        //Iterate through and remove dime
                        if (register[i].name == "Dime")
                        {
                            // Add removed coins to hopper
                            hopperOut.Add(register[i]);
                            register.RemoveAt(i);                        // Remove coin from register
                            changeDue = Math.Round(changeDue - 0.10, 2); // Decrease change due
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            while (Math.Round(changeDue, 2) >= 0.05)
            {
                bool coinExists = Verification.CheckIfObjectExists(register, "Nickel");
                if (coinExists)
                {
                    for (int i = 0; i < register.Count; i++)
                    {
                        //Iterate throu and remove Nickel
                        if (register[i].name == "Nickel")
                        {
                            //Add remove coins to hopper
                            hopperOut.Add(register[i]);
                            register.RemoveAt(i);                        // Remove coin from register
                            changeDue = Math.Round(changeDue - 0.05, 2); // Decrease change due
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            while (Math.Round(changeDue, 2) > 0)
            {
                bool coinExists = Verification.CheckIfObjectExists(register, "Penny");
                if (coinExists)
                {
                    for (int i = 0; i < register.Count; i++)
                    {
                        // Iterate through and remove penny
                        if (register[i].name == "Penny")
                        {
                            //Add removed coins to hopper
                            hopperOut.Add(register[i]);
                            register.RemoveAt(i);                        // Remove coin from register
                            changeDue = Math.Round(changeDue - 0.01, 2); // Decrease change due
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            // Add removed coins to hopper, dispense only if reach even change
            if (Math.Round(changeDue, 2) == 0.00)
            {
                canGiveExactChange = true;
                // Transfer coins from hopper to customer
                return(canGiveExactChange);
            }
            else
            {
                // Return coins to machine register
                return(canGiveExactChange);
            }
        }
Esempio n. 3
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);
        }