Example #1
0
        public void RemoveChangeFromMachine(double returnChange)
        {
            while (returnChange > 0.001 && sodaMachine.register.Count > 0)
            {
                while (returnChange >= 0.25)
                {
                    for (int i = 0; i < sodaMachine.register.Count; i++)
                    {
                        if (sodaMachine.register[i].name == "Quarter")
                        {
                            Coin   coinReturnToWallet = sodaMachine.register[i];
                            string coinName           = sodaMachine.register[i].name;
                            sodaMachine.register.RemoveAt(i);
                            simulatedCoin.Add(coinReturnToWallet);
                            returnChange -= sodaMachine.register[i].Value;
                            returnChange  = Math.Round(returnChange, 2);
                        }
                    }
                }
                while (returnChange >= 0.10)
                {
                    for (int i = 0; i < sodaMachine.register.Count; i++)
                    {
                        if (sodaMachine.register[i].name == "Dime" && returnChange >= 0.10)
                        {
                            Coin   coinReturnToWallet = sodaMachine.register[i];
                            string coinName           = sodaMachine.register[i].name;
                            sodaMachine.register.RemoveAt(i);
                            simulatedCoin.Add(coinReturnToWallet);
                            returnChange -= sodaMachine.register[i].Value;
                            returnChange  = Math.Round(returnChange, 2);
                        }
                    }
                }

                while (returnChange >= 0.05)
                {
                    for (int i = 0; i < sodaMachine.register.Count; i++)
                    {
                        if (sodaMachine.register[i].name == "Nickel" && returnChange >= 0.05)
                        {
                            Coin   coinReturnToWallet = sodaMachine.register[i];
                            string coinName           = sodaMachine.register[i].name;
                            sodaMachine.register.RemoveAt(i);
                            simulatedCoin.Add(coinReturnToWallet);
                            returnChange -= sodaMachine.register[i].Value;
                            returnChange  = Math.Round(returnChange, 2);
                        }
                    }
                }
                while (returnChange > 0.01)
                {
                    for (int i = 0; i < sodaMachine.register.Count; i++)
                    {
                        if (sodaMachine.register[i].name == "Penny" && returnChange >= 0.001)
                        {
                            Coin   coinReturnToWallet = sodaMachine.register[i];
                            string coinName           = sodaMachine.register[i].name;
                            sodaMachine.register.RemoveAt(i);
                            simulatedCoin.Add(coinReturnToWallet);
                            returnChange -= sodaMachine.register[i].Value;
                            returnChange  = Math.Round(returnChange, 2);
                        }
                    }
                }
            }
        }
Example #2
0
        public void MasterMethod()
        {
            bool   hasSoda      = false;
            bool   hasPaid      = false;
            string selectedSoda = UserInterface.SelectSodaToBuy();

            UserInterface.DisplaySodaCost(selectedSoda);
            string changeSelected  = UserInterface.SelectChange();
            double valueOfCoin     = CheckHowMuchMoneyEntered(changeSelected);
            double amountLeftToPay = ComparePaidCost(selectedSoda, valueOfCoin);

            hasPaid = CheckIfPaid(amountLeftToPay);
            while (hasPaid == true)
            {
                hasSoda = CheckIfSodaStocked(selectedSoda);
                if (hasSoda == true)
                {
                    double returnChange = CheckIfNegative(amountLeftToPay);
                    RemoveChangeFromMachine(returnChange);
                    bool willDispense = SimulatedCompareToActual(returnChange);
                    MoveCoinFromSimulatedToMachine();
                    if (willDispense == true)
                    {
                        DispenseSoda(selectedSoda);
                        hasPaid = true;
                    }
                    else
                    {
                        GiveFullPaymentBack(amountLeftToPay, selectedSoda);
                    }
                }
                break;
            }
            while (hasPaid == false)
            {
                amountLeftToPay = ComparePaidCost(selectedSoda, valueOfCoin);
                Coin payment = customer.RemoveChange(changeSelected);
                SimulatePaymentTotal(payment);

                if (amountLeftToPay <= 0)
                {
                    hasSoda = CheckIfSodaStocked(selectedSoda);
                    if (hasSoda == true)
                    {
                        double returnChange = CheckIfNegative(amountLeftToPay);
                        RemoveChangeFromMachine(returnChange);
                        bool willDispense = SimulatedCompareToActual(returnChange);
                        MoveCoinFromSimulatedToMachine();
                        if (willDispense == true)
                        {
                            DispenseSoda(selectedSoda);
                            hasPaid = true;
                        }
                        else
                        {
                            GiveFullPaymentBack(amountLeftToPay, selectedSoda);
                        }
                    }
                    else
                    {
                        GiveFullPaymentBack(amountLeftToPay, selectedSoda);
                    }
                }
                else
                {
                    UserInterface.DisplayOutstandingPayment(amountLeftToPay);
                    bool hasMoney = UserInterface.AskIfHaveMoreMoneyToAdd();
                    if (hasMoney == true)
                    {
                        string continueTransaction = UserInterface.TakeUserInputForContinue();
                        if (continueTransaction == "1")
                        {
                            changeSelected = UserInterface.SelectChange();
                            valueOfCoin    = CheckHowMuchMoneyEntered(changeSelected);
                            payment        = customer.RemoveChange(changeSelected);
                            SimulatePaymentTotal(payment);
                            amountLeftToPay = FinishRemainingBalance(amountLeftToPay, valueOfCoin);
                            double returnChange = CheckIfNegative(amountLeftToPay);
                            MoveCoinFromSimulatedToMachine();
                            RemoveChangeFromMachine(returnChange);
                            bool willDispense = SimulatedCompareToActual(returnChange);
                            if (willDispense == true)
                            {
                                DispenseSoda(selectedSoda);
                                hasPaid = true;
                            }
                            else
                            {
                                GiveFullPaymentBack(amountLeftToPay, selectedSoda);
                            }
                        }
                        else
                        {
                            GiveFullPaymentBack(amountLeftToPay, selectedSoda);
                        }
                    }
                }
                break;
            }
        }
Example #3
0
 public void ReturnChangeToMachine(Coin coinReturnToMachine)
 {
     sodaMachine.register.Add(coinReturnToMachine);
 }
Example #4
0
 public void SimulatePaymentTotal(Coin payment)
 {
     simulatedCoin.Add(payment);
 }
Example #5
0
 public void ReturnChangeToWallet(Coin coinReturnToWallet)
 {
     customer.wallet.coins.Add(coinReturnToWallet);
 }