Пример #1
0
        private void Refund()
        {
            bool change = CheckForChange();

            if (change == false)
            {
                Console.WriteLine("Not enough change in machine.");
                Console.ReadLine();
                return;
            }
            Quarter quarter = new Quarter();
            Dime    dime    = new Dime();
            Nickle  nickle  = new Nickle();
            Penny   penny   = new Penny();

            while (refundAmount > 0)
            {
                refundAmount = Math.Round(refundAmount, 2);
                if (refundAmount - quarter.value >= quarter.value)
                {
                    refundAmount -= quarter.value;
                    refund.Add(new Quarter());
                    quarters.RemoveAt(0);
                }
                else if (refundAmount - dime.value >= dime.value)
                {
                    refundAmount -= dime.value;
                    refund.Add(new Dime());
                    dimes.RemoveAt(0);
                }
                else if (refundAmount - nickle.value >= nickle.value)
                {
                    refundAmount -= nickle.value;
                    refund.Add(new Nickle());
                    nickles.RemoveAt(0);
                }
                else
                {
                    refundAmount -= penny.value;
                    refund.Add(new Penny());
                    pennies.RemoveAt(0);
                }
            }
        }
Пример #2
0
        private bool CheckForChange()
        {
            Quarter quarter = new Quarter();
            Dime    dime    = new Dime();
            Nickle  nickle  = new Nickle();
            Penny   penny   = new Penny();
            double  machineChange;

            machineChange = quarters.Count() * quarter.value;
            machineChange = machineChange + (dimes.Count() * dime.value);
            machineChange = machineChange + (nickles.Count() * nickle.value);
            machineChange = machineChange + (pennies.Count() * penny.value);
            if (machineChange < refundAmount)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }