Example #1
0
 public void DisplayAllStats() // Display current state of simulation - see how objects have changed hands throughout transaction
 {
     Console.WriteLine("\nPress enter to display all current simulation statistics: ");
     Console.ReadLine();
     Console.Clear();
     Console.WriteLine("Soda machine:" +
                       $"\n{sodaMachine.inventory.Count} cans in inventory" +
                       $"\n{sodaMachine.register.Count} coins in register totalling {Verification.CountMoney(sodaMachine.register):C2}" +
                       $"\n{sodaMachine.CardPaymentBalance:C2} in card credits.\n");
     Console.WriteLine("Customer:" +
                       $"\nCard balance of {customer.wallet.card.AvailableFunds:C2}" +
                       $"\nWallet contains {Verification.CountMoney(customer.wallet.coins):C2}");
     customer.DisplayContents(customer.backpack);
 }
Example #2
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);
        }
Example #3
0
        private bool DispenseChange(double changeDue)
        {
            // Calculate total change available, ensure than change available is greater than change due
            bool canGiveExactChange = false;

            while (Math.Round(changeDue, 2) >= 0.25)
            {
                bool coinExists = Verification.CheckIfObjectExists(register, "Quarter");// Check if quarters exist
                if (coinExists)
                {
                    for (int i = 0; i < register.Count; i++)
                    {
                        if (register[i].name == "Quarter")               // Iterate through and remove quarter
                        {
                            hopperOut.Add(register[i]);                  // Add removed coins to hopper
                            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++)
                    {
                        if (register[i].name == "Dime")                  // Iterate through and remove quarter
                        {
                            hopperOut.Add(register[i]);                  // Add removed coins to hopper
                            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++)
                    {
                        if (register[i].name == "Nickel")                // Iterate through and remove quarter
                        {
                            hopperOut.Add(register[i]);                  // Add removed coins to hopper
                            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++)
                    {
                        if (register[i].name == "Penny")                 // Iterate through and remove quarter
                        {
                            hopperOut.Add(register[i]);                  // Add removed coins to hopper
                            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);
            }
        }