コード例 #1
0
        // chooses a soda and dispense it as a can
        public Can ChooseASoda()
        {
            userChoice = StaticUserInterface.DisplaySodaOptions();

            Can can;

            switch (userChoice)
            {
            case "1":
                can = inventory.Find(x => x.name == "Bundaberg Root Beer");

                return(can);

            case "2":
                can = inventory.Find(x => x.name == "Pepsi");

                return(can);

            case "3":
                can = inventory.Find(x => x.name == "Fanta");

                return(can);

            default:
                Console.WriteLine("Please pick between 1-3");
                return(ChooseASoda());
            }
        }
コード例 #2
0
ファイル: Customer.cs プロジェクト: kadirermaya/SodaMachine
        // method takes the coin from wallet and adds to deposit
        public Coin InsertMoney(Coin coin)
        {
            switch (userInput)
            {
            case "1":
                coin = wallet.coins.Find(x => x.name == "Quarter");
                if (coin != null)
                {
                    deposit.Add(coin);
                    CalculateDeposit();
                    RemoveCoinFromWallet(coin);
                    return(coin);
                }
                StaticUserInterface.Display($"You don't have Quarter in your wallet! Pick another one!");
                return(InsertMoney(PickPayment()));

            case "2":
                coin = wallet.coins.Find(x => x.name == "Dime");
                if (coin != null)
                {
                    deposit.Add(coin);
                    CalculateDeposit();
                    RemoveCoinFromWallet(coin);
                    return(coin);
                }
                StaticUserInterface.Display($"You don't have Dime in your wallet! Pick another one!");
                return(InsertMoney(PickPayment()));

            case "3":
                coin = wallet.coins.Find(x => x.name == "Nickel");
                if (coin != null)
                {
                    deposit.Add(coin);
                    CalculateDeposit();
                    RemoveCoinFromWallet(coin);
                    return(coin);
                }
                StaticUserInterface.Display($"You don't have Nickel in your wallet! Pick another one!");
                return(InsertMoney(PickPayment()));

            case "4":
                coin = wallet.coins.Find(x => x.name == "Penny");
                if (coin != null)
                {
                    deposit.Add(coin);
                    CalculateDeposit();
                    RemoveCoinFromWallet(coin);
                    return(coin);
                }
                StaticUserInterface.Display($"You don't have Penny in your wallet! Pick another one!");
                return(InsertMoney(PickPayment()));

            default:
                Console.WriteLine("Please pick money to deposit.");
                return(InsertMoney(coin));
            }
        }
コード例 #3
0
ファイル: Simulation.cs プロジェクト: kadirermaya/SodaMachine
        public void Run()
        {
            StaticUserInterface.WelcomeScreen();
            StaticUserInterface.DisplayProducts();
            while (addMoreMoney)
            {
                customer.InsertMoney(customer.PickPayment());
                Console.Clear();
                StaticUserInterface.WelcomeScreen();
                StaticUserInterface.DisplayProducts();
                Console.WriteLine($"\nYour deposit: {customer.depositAmount}");
                string userInput = StaticUserInterface.DisplayAskAddMoreMoney();
                if (userInput == "no")
                {
                    addMoreMoney = false;
                    Console.WriteLine("");
                    Console.Clear();
                    StaticUserInterface.WelcomeScreen();
                    StaticUserInterface.DisplayProducts();
                    Console.WriteLine($"\nYour deposit: {customer.depositAmount}");
                }
            }

            Can choosenSoda = sodaMachine.ChooseASoda();

            // this statement gives deposit back if there is no soda in the machine
            if (choosenSoda == null)
            {
                Console.WriteLine($"I don't have {choosenSoda.name}. Get your deposit back!");
                AddDepositToWallet();
            }

            else if (choosenSoda.Cost == customer.depositAmount)
            {
                sodaMachine.AddDepositToRegister(customer.deposit);
                sodaMachine.DispenseSoda(choosenSoda);
                Console.WriteLine($"Enjoy with your {choosenSoda.name}");
                customer.AddCansToBackpack(choosenSoda);
                // make the deposit empty
                customer.deposit = new List <Coin>();
            }

            else if (choosenSoda.Cost < customer.depositAmount)
            {
                sodaMachine.AddDepositToRegister(customer.deposit);
                double changeAmount = Math.Round(CalculateTheChange(choosenSoda), 2);
                change = sodaMachine.GiveChange(changeAmount);
                if (change == null)
                {
                    AddDepositToWallet();
                    StaticUserInterface.DisplayRegisterHasNoChange();
                }
                else
                {
                    sodaMachine.DispenseSoda(choosenSoda);
                    Console.WriteLine($"Enjoy with your {choosenSoda.name}");
                    customer.AddCansToBackpack(choosenSoda);
                    AddChangeToWallet();
                }
            }
            else
            {
                // if not enough money passed in don`t complete the transaction.
                Console.WriteLine("You don't have enough money! Get your deposit back!");
                AddDepositToWallet();
            }
        }