예제 #1
0
 //Cancle coin transaction
 public void CancelTransaction(Customer customer)
 {
     //soda machine returns coins from hopper in
     foreach (Coin coin in hopperIn.ToList())
     {
         customer.wallet.coins.Add(coin);
         hopperIn.Remove(coin);
     }
     Console.WriteLine($"The soda machine register now contains {Verification.CountMoney(register),2:C2}");
     customer.DisplayContents(customer.backpack);
     customer.DisplayContents(customer.wallet);
 }
예제 #2
0
 //Display "state" of simulation. (how objects change throughout transaction process
 public void DisplayAllStats()
 {
     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);
 }
예제 #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);
                }
            }
        }
예제 #4
0
 //Complete coin transaction
 public void CompleteTransaction(Customer customer, string userSelection)
 {
     //soda machine takes coins from hopper
     foreach (Coin coin in hopperIn.ToList())
     {
         register.Add(coin);
         hopperIn.Remove(coin);
     }
     Console.WriteLine($"The soda machine register now contains {Verification.CountMoney(register),2:C2}");
     //Soda machine puts soda in backpack
     customer.backpack.cans.Add(DispenseSoda(userSelection));
     customer.DisplayContents(customer.backpack);
     //soda machine gives change
     foreach (Coin coin in hopperOut.ToList())
     {
         customer.wallet.coins.Add(coin);
         hopperOut.Remove(coin);
     }
     customer.DisplayContents(customer.wallet);
 }
예제 #5
0
        // member methods
        //Need to display customer contents (wallet)
        public void DisplayContents(Wallet wallet)
        {
            double amountInWallet = Math.Round(Verification.CountMoney(wallet.coins), 2);

            Console.WriteLine($"You have {amountInWallet:C2} in coins in your wallet.");
            int numberOfQuarters = 0;
            int numberOfDimes    = 0;
            int numberOfNickels  = 0;
            int numberOfPennies  = 0;

            if (wallet.coins.Count == 0)
            {
                Console.WriteLine("You have no coins in your wallet.");
            }
            else
            {
                foreach (Coin coin in wallet.coins)
                {
                    switch (coin.name)
                    {
                    case "Quarter":
                        numberOfQuarters++;
                        break;

                    case "Dime":
                        numberOfDimes++;
                        break;

                    case "Nickel":
                        numberOfNickels++;
                        break;

                    case "Penny":
                        numberOfPennies++;
                        break;
                    }
                }
                Console.WriteLine($"Your wallet contains {numberOfQuarters} quarters, {numberOfDimes} dimes, {numberOfNickels} nickels, and {numberOfPennies} pennies.");
            }
        }
예제 #6
0
        // COIN TRANSACTIONS //

        //Process coin transaction
        public bool ProcessTransaction(string userInput)
        {
            bool canCompleteTransaction;
            //tally coins in hopper
            double moneyInHopper = Math.Round(Verification.CountMoney(hopperIn), 2);
            //get soda cost
            double sodaCost = Math.Round(GetSodaCost(userInput), 2);

            if (sodaCost > moneyInHopper)
            {
                Console.WriteLine("\nTransaction cannot be completed - inadequate funds.");
                canCompleteTransaction = false;
            }
            else if (sodaCost == moneyInHopper)
            {
                Console.WriteLine("\nTransaction complete, no change due!");
                canCompleteTransaction = true;
            }
            else
            {
                //Calculate change for user
                double changeDue = Math.Round(moneyInHopper - sodaCost, 2);
                //Checks if exact change can be given to user
                bool canGiveExactChange = DispenseChange(changeDue);
                if (canGiveExactChange == true)
                {
                    Console.WriteLine("\nTransaction complete, pleace collect your change!");
                    canCompleteTransaction = true;
                }
                else
                {
                    Console.WriteLine("\nTransaction cannot be completed - exact change unavailable.");
                    canCompleteTransaction = false;
                }
            }
            return(canCompleteTransaction);
        }