Пример #1
0
        private double CountChange(int quarters, int dimes, int nickels, int pennies)
        {
            Quarter quarter = new Quarter();
            Dime    dime    = new Dime();
            Nickel  nickle  = new Nickel();
            Penny   penny   = new Penny();
            double  value   = 0;

            value += quarter.Value * quarters;
            value += dime.Value * dimes;
            value += nickle.Value * nickels;
            value += penny.Value * pennies;

            return(value);
        }
Пример #2
0
        //Takes in the value of the amount of change needed.
        //Attempts to gather all the required coins from the sodamachine's register to make change.
        //Returns the list of coins as change to despense.
        //If the change cannot be made, return null.
        private List <Coin> GatherChange(double changeValue)
        {
            List <Coin> coins   = new List <Coin>();
            Quarter     quarter = new Quarter();
            Dime        dime    = new Dime();
            Nickel      nickel  = new Nickel();
            Penny       penny   = new Penny();


            while (changeValue >= 0.25)
            {
                if (RegisterHasCoin("Quarter"))
                {
                    _register.Remove(quarter);
                    coins.Add(quarter);
                    changeValue = changeValue - quarter.Value;
                }
            }
            while (changeValue >= 0.10)
            {
                if (RegisterHasCoin("Dime"))
                {
                    _register.Remove(dime);
                    coins.Add(dime);
                    changeValue = changeValue - dime.Value;
                }
            }
            while (changeValue >= 0.05)
            {
                if (RegisterHasCoin("Nickel"))
                {
                    _register.Remove(nickel);
                    coins.Add(nickel);
                    changeValue = changeValue - nickel.Value;
                }
            }
            while (changeValue >= 0.01)
            {
                if (RegisterHasCoin("Penny"))
                {
                    _register.Remove(penny);
                    coins.Add(penny);
                    changeValue = changeValue - penny.Value;
                }
            }
            return(coins);
            //return list of coins coins
        }
Пример #3
0
        //Constructor (Spawner)
        public Wallet()
        {
            Coins = new List <Coin>();

            Quarter quarter = new Quarter();
            Dime    dime    = new Dime();
            Nickel  nickle  = new Nickel();
            Penny   penny   = new Penny();

            FillRegister(quarter, 12);
            FillRegister(dime, 10);
            FillRegister(nickle, 20);
            FillRegister(penny, 25);

            // FillRegister();
        }
Пример #4
0
        //member methods
        private void fillSodaMachine()
        {
            quarter    = new Quarter();
            dime       = new Dime();
            nickel     = new Nickel();
            penny      = new Penny();
            orangeSoda = new OrangeSoda();
            rootBeer   = new RootBeer();
            cola       = new Cola();
            Functions.CreateCans(cola, 5, inventory);
            Functions.CreateCans(orangeSoda, 9, inventory);
            Functions.CreateCans(rootBeer, 1, inventory);

            Functions.CreateCoins(quarter, 20, register); //20
            Functions.CreateCoins(dime, 10, register);    //10
            Functions.CreateCoins(nickel, 20, register);  //20
            Functions.CreateCoins(penny, 50, register);   //50
        }
Пример #5
0
        public static double WhatsInMyWallet(Wallet wallet)
        {
            Quarter quarter = new Quarter();
            Dime    dime    = new Dime();
            Nickel  nickel  = new Nickel();
            Penny   penny   = new Penny();

            int    quarters = 0;
            int    dimes    = 0;
            int    nickels  = 0;
            int    pennies  = 0;
            double value    = 0;

            foreach (Coin coin in wallet.coins)
            {
                if (coin.name == quarter.name)
                {
                    quarters -= -1;
                }
                else if (coin.name == dime.name)
                {
                    dimes -= -1;
                }
                else if (coin.name == nickel.name)
                {
                    nickels -= -1;
                }
                else if (coin.name == penny.name)
                {
                    pennies -= -1;
                }
                else
                {
                    Console.WriteLine("something went wrong counting coins. Contact the developer of this application. : WhatsInMyWallet()");
                }

                value += coin.Value;
            }
            Console.WriteLine($"You have {quarters} quarters, {dimes} dimes, {nickels} nickels, and {pennies} pennies, totalling {value.ToString("c")}  in your wallet.");
            Console.WriteLine("press any key to continue.");
            Console.ReadKey();

            return(value);
        }
Пример #6
0
        //public int quarterCount;
        public Wallet()
        {
            coins = new List <Coin>();
            //quarterCount = 1;
            Quarter quarter = new Quarter();

            PopulateDefaultWallet(10, quarter);

            Dime dime = new Dime();

            PopulateDefaultWallet(10, dime);

            Nickel nickel = new Nickel();

            PopulateDefaultWallet(10, nickel);

            Penny penny = new Penny();

            PopulateDefaultWallet(50, penny);
        }
Пример #7
0
        public void AddCoinsToRegisterForPurchase(Can can)
        {
            double remainingChangeAmountToAdd = can.Cost;

            while () // while there is still change to be added to the register
            {
                // determine what coin to add to the register (using division?)
                // create (instantiate) the coin object to add to the register
                // add the created coin object to the register
                // lower the value of 'remainingChangeAmountToAdd by the value of the coin that was just added

                //Quarter quarter = new Quarter();
                //Dime dime = new Dime();


                if (remainingChangeAmountToAdd > .25) // we can add a quarter
                {
                    Quarter quarter = new Quarter();
                    register.Add(quarter);
                    remainingChangeAmountToAdd -= quarter.Value;
                }
                else if (remainingChangeAmountToAdd > .10) // we should add a dime next
                {
                    Dime dime = new Dime();
                    register.Add(dime);
                    remainingChangeAmountToAdd -= dime.Value;
                }
                else if (remainingChangeAmountToAdd > .05)
                {
                    Nickle nickle = new Nickle();
                    register.Add(nickle);
                    remainingChangeAmountToAdd -= nickle.Value;
                }
                else
                {
                    Penny penny = new Penny();
                    register.Add(penny);
                    remainingChangeAmountToAdd -= penny.Value;
                }
            }
        }
Пример #8
0
        //Member Methods (Can Do)
        //Fills wallet with starting money
        private void FillRegister()
        {
            double totalCash = 0;

            while (totalCash < 5)
            {
                totalCash = 0;
                Penny   penny   = new Penny();
                Nickel  nickel  = new Nickel();
                Dime    dime    = new Dime();
                Quarter quarter = new Quarter();
                Coins.Add(penny);
                Coins.Add(nickel);
                Coins.Add(dime);
                Coins.Add(quarter);
                foreach (Coin coin in Coins)
                {
                    totalCash += coin.Value;
                }
            }
        }
Пример #9
0
        public List <Coin> CreateChange(double changeValue)
        {
            double      change        = changeValue;
            List <Coin> createdChange = new List <Coin>();

            new List <Coin>();
            while (change > 0)
            {
                if (change >= 0.25)
                {
                    change = change - 0.25 + 0.000001;
                    Quarter quarter = new Quarter();
                    createdChange.Add(quarter);
                }
                else if (change >= 0.10)
                {
                    change -= 0.10 + 0.000001;
                    Dime dime = new Dime();
                    createdChange.Add(dime);
                }
                else if (change >= 0.05)
                {
                    change -= 0.05 + 0.000001;
                    Nickle nickle = new Nickle();
                    createdChange.Add(nickle);
                }
                else if (change >= 0.009997999999999993)
                {
                    change -= .01;
                    Penny penny = new Penny();
                    createdChange.Add(penny);
                }
                else
                {
                    break;
                }
            }
            return(createdChange);
        }
Пример #10
0
        //Constructor (Spawner)
        public SodaMachine()
        {
            _register  = new List <Coin>();
            _inventory = new List <Can>();

            Quarter quarter = new Quarter();
            Dime    dime    = new Dime();
            Nickel  nickle  = new Nickel();
            Penny   penny   = new Penny();

            FillRegister(quarter, 20);
            FillRegister(dime, 10);
            FillRegister(nickle, 20);
            FillRegister(penny, 50);

            RootBeer   rootBeer   = new RootBeer();
            Cola       cola       = new Cola();
            OrangeSoda orangeSoda = new OrangeSoda();

            FillInventory(rootBeer, 10);
            FillInventory(cola, 10);
            FillInventory(orangeSoda, 10);
        }
Пример #11
0
        //Constructor (Spawner)
        public SodaMachine()
        {
            _register  = new List <Coin>();
            _inventory = new List <Can>();

            RootBeer   rootBeer   = new RootBeer();
            Cola       cola       = new Cola();
            OrangeSoda orangeSoda = new OrangeSoda();

            FillInventory(20, rootBeer);
            FillInventory(20, cola);
            FillInventory(20, orangeSoda);

            Quarter quarter = new Quarter();
            Dime    dime    = new Dime();
            Nickel  nickel  = new Nickel();
            Penny   penny   = new Penny();

            FillRegister(20, quarter);
            FillRegister(10, dime);
            FillRegister(20, nickel);
            FillRegister(50, penny);
        }
Пример #12
0
 void AddCoins()
 {   // member method
     for (int i = 0; i < 6; i++)
     {
         Quarter quarter = new Quarter();
         coin.Add(quarter);
     }
     for (int i = 0; i < 20; i++)
     {
         Dime dime = new Dime();
         coin.Add(dime);
     }
     for (int i = 0; i < 20; i++)
     {
         Nickel nickel = new Nickel();
         coin.Add(nickel);
     }
     for (int i = 0; i < 50; i++)
     {
         Penny penny = new Penny();
         coin.Add(penny);
     }
 }
Пример #13
0
        //Member Methods (Can Do)

        //A method to fill the sodamachines register with coin objects.
        public void FillRegister()
        {
            for (int i = 0; i < 20; i++)
            {
                Coin myCoin = new Quarter();
                _register.Add(myCoin);
            }
            for (int i = 0; i < 10; i++)
            {
                Coin myCoin = new Dime();
                _register.Add(myCoin);
            }
            for (int i = 0; i < 20; i++)
            {
                Coin myCoin = new Nickel();
                _register.Add(myCoin);
            }
            for (int i = 0; i < 50; i++)
            {
                Coin myCoin = new Penny();
                _register.Add(myCoin);
            }
        }
Пример #14
0
 public void AddCoins()
 {
     for (int i = 0; i < 12; i++)
     {
         quarter = new Quarter();
         coins.Add(quarter);
     }
     for (int i = 0; i < 13; i++)
     {
         dime = new Dime();
         coins.Add(dime);
     }
     for (int i = 0; i < 12; i++)
     {
         nickel = new Nickel();
         coins.Add(nickel);
     }
     for (int i = 0; i < 10; i++)
     {
         penny = new Penny();
         coins.Add(penny);
     }
 }
Пример #15
0
 //member methods
 public void FillWallet()
 {
     for (int i = 0; i < 12; i++)
     {
         quarter = new Quarter();
         coins.Add(quarter);
     }
     for (int i = 0; i < 10; i++)
     {
         dime = new Dime();
         coins.Add(dime);
     }
     for (int i = 0; i < 10; i++)
     {
         nickle = new Nickle();
         coins.Add(nickle);
     }
     for (int i = 0; i < 10; i++)
     {
         penny = new Penny();
         coins.Add(penny);
     }
 }
Пример #16
0
 //Methods(Can Do)
 public void InsertChangeInRegister()
 {
     for (int i = 0; i < 20; i++)
     {
         Quarter quarter = new Quarter();
         register.Add(quarter);
     }
     for (int i = 0; i < 10; i++)
     {
         Dime dime = new Dime();
         register.Add(dime);
     }
     for (int i = 0; i < 20; i++)
     {
         Nickle nickle = new Nickle();
         register.Add(nickle);
     }
     for (int i = 0; i < 50; i++)
     {
         Penny penny = new Penny();
         register.Add(penny);
     }
 }
Пример #17
0
 //Member Methods (Can Do)
 //Fills wallet with starting money
 private void FillRegister()
 {
     for (int i = 0; i <= 10; i++)
     {
         Quarter quarter = new Quarter();
         Coins.Add(quarter);
     }
     for (int i = 0; i <= 10; i++)
     {
         Dime dime = new Dime();
         Coins.Add(dime);
     }
     for (int i = 0; i <= 20; i++)
     {
         Nickel nickel = new Nickel();
         Coins.Add(nickel);
     }
     for (int i = 0; i <= 50; i++)
     {
         Penny penny = new Penny();
         Coins.Add(penny);
     }
 }
Пример #18
0
        //Member Methods (CAN DO)

        public void amountOfCoins()
        {
            for (int i = 0; i < 20; i++)
            {
                Quarter quarter = new Quarter();
                Quarters.Add(quarter);
            }
            for (int i = 0; i < 20; i++)
            {
                Nickel nickel = new Nickel();
                Nickels.Add(nickel);
            }
            for (int i = 0; i < 10; i++)
            {
                Dime dime = new Dime();
                Dimes.Add(dime);
            }
            for (int i = 0; i < 50; i++)
            {
                Penny penny = new Penny();
                Pennies.Add(penny);
            }
        }
Пример #19
0
 public void StartingWallet(int quarters, int dimes, int nickels, int pennies)
 {
     for (int i = 0; i < quarters; i++)
     {
         Quarter quarter = new Quarter();
         coins.Add(quarter);;
     }
     for (int i = 0; i < dimes; i++)
     {
         Dime dime = new Dime();
         coins.Add(dime);
     }
     for (int i = 0; i < nickels; i++)
     {
         Nickel nickel = new Nickel();
         coins.Add(nickel);
     }
     for (int i = 0; i < pennies; i++)
     {
         Penny penny = new Penny();
         coins.Add(penny);
     }
 }
Пример #20
0
        //Member Methods (Can Do)

        //A method to fill the sodamachines register with coin objects.
        public void FillRegister()
        {
            for (int i = 0; i < 20; i++)
            {
                Quarter quarter = new Quarter();
                _register.Add(quarter);
            }
            for (int i = 0; i < 10; i++)
            {
                Dime dime = new Dime();
                _register.Add(dime);
            }
            for (int i = 0; i < 20; i++)
            {
                Nickel nickel = new Nickel();
                _register.Add(nickel);
            }
            for (int i = 0; i < 50; i++)
            {
                Penny penny = new Penny();
                _register.Add(penny);
            }
        }
Пример #21
0
 //Methods(Can Do)
 public void MoneyInWallet()
 {
     for (int i = 0; i < 4; i++)
     {
         Quarter quarter = new Quarter();
         coins.Add(quarter);
     }
     for (int i = 0; i < 10; i++)
     {
         Dime dime = new Dime();
         coins.Add(dime);
     }
     for (int i = 0; i < 20; i++)
     {
         Nickle nickle = new Nickle();
         coins.Add(nickle);
     }
     for (int i = 0; i < 100; i++)
     {
         Penny penny = new Penny();
         coins.Add(penny);
     }
 }
Пример #22
0
 private void StartingChange()
 {
     for (int i = 0; i < 12; i++)
     {
         Quarter quarter = new Quarter();
         customerCoins.Add(quarter);
     }
     for (int i = 0; i < 10; i++)
     {
         Dime dime = new Dime();
         customerCoins.Add(dime);
     }
     for (int i = 0; i < 10; i++)
     {
         Nickle nickle = new Nickle();
         customerCoins.Add(nickle);
     }
     for (int i = 0; i < 50; i++)
     {
         Penny penny = new Penny();
         customerCoins.Add(penny);
     }
 }
Пример #23
0
        public static string PickCoins()
        {
            Console.WriteLine("Select which coins you would like to use to pay: \n" + "--- ( 1 ) = Penny --- \n" + "--- ( 2 ) = Nickle --- \n"
                              + "--- ( 3 ) = Dime --- \n" + "--- ( 4 ) = Quarter --- \n");
            ConsoleKeyInfo thing = Console.ReadKey();
            Coin           coin;

            if (thing.Key == ConsoleKey.D1)
            {
                coin = new Penny("Penny");
                Console.WriteLine(" You have deposited .01 cents!");
                return("Penny");
            }
            else if (thing.Key == ConsoleKey.D2)
            {
                coin = new Nickle("Nickle");
                Console.WriteLine(" You have deposited .05 cents!");
                return("Nickle");
            }
            else if (thing.Key == ConsoleKey.D3)
            {
                coin = new Dime("Dime");
                Console.WriteLine(" You have deposited .10 cents!");
                return("Dime");
            }
            else if (thing.Key == ConsoleKey.D4)
            {
                coin = new Quarter("Quarter");
                Console.WriteLine(" You have deposited .25 cents!");
                return("Quarter");
            }
            else
            {
                Console.Clear();
                return("nothing");
            }
        }
        public SodaMachine()
        {
            register = new List <Coin>();
            for (int index = 0; index < 20; index++)
            {
                Quarter quarter = new Quarter();
                register.Add(quarter);
            }
            for (int index = 0; index < 10; index++)
            {
                Dime dime = new Dime();
                register.Add(dime);
            }
            for (int index = 0; index < 20; index++)
            {
                Nickle nickle = new Nickle();
                register.Add(nickle);
            }
            for (int index = 0; index < 50; index++)
            {
                Penny penny = new Penny();
                register.Add(penny);
            }

            inventory = new List <Can>();
            for (int index = 0; index < 20; index++)
            {
                Cola       cola       = new Cola();
                OrangeSoda orangeSoda = new OrangeSoda();
                RootBeer   rootBeer   = new RootBeer();

                inventory.Add(cola);
                inventory.Add(orangeSoda);
                inventory.Add(rootBeer);
            }
        }
Пример #25
0
        //Takes in a list of coin objects to add into the customers wallet.
        public void AddCoinsIntoWallet(List <Coin> coinsToAdd)
        {
            Quarter quarter = new Quarter();
            Dime    dime    = new Dime();
            Nickel  nickel  = new Nickel();
            Penny   penny   = new Penny();

            for (int i = 0; i < 10; i++)
            {
                Wallet.Coins.Add(quarter);
            }
            for (int i = 0; i < 23; i++)
            {
                Wallet.Coins.Add(dime);
            }
            for (int i = 0; i < 172; i++)
            {
                Wallet.Coins.Add(nickel);
            }
            for (int i = 0; i < 19; i++)
            {
                Wallet.Coins.Add(penny);
            }
        }
Пример #26
0
 public Wallet()
 {
     coins = new List <Coin>();
     for (int i = 0; i < 12; i++)
     {
         Quarter quarter = new Quarter();
         coins.Add(quarter);
     }
     for (int i = 0; i < 10; i++)
     {
         Dime dime = new Dime();
         coins.Add(dime);
     }
     for (int i = 0; i < 10; i++)
     {
         Nickle nickle = new Nickle();
         coins.Add(nickle);
     }
     for (int i = 0; i < 50; i++)
     {
         Penny penny = new Penny();
         coins.Add(penny);
     }
 }
Пример #27
0
        public void StockChangeInMachine()
        {
            for (int i = 0; i <= 10; i++)
            {
                Dime dime = new Dime();
                coins.Add(dime);
            }



            for (int i = 0; i <= 20; i++)
            {
                Quarter quarter = new Quarter();
                coins.Add(quarter);
            }



            for (int i = 0; i <= 20; i++)
            {
                Nickel nickel = new Nickel();
                coins.Add(nickel);
            }



            for (int i = 0; i <= 50; i++)
            {
                Penny penny = new Penny();
                coins.Add(penny);
            }
            // these errors are new that i dont under stand at first it says can
            //priceGrape was to restricted so i changed the variable from inventory to public
            if (coins < canPriceGrape)                              // now thw whole thing is a error whould like clarity


            {// wasnt sure how to return money
                Console.WriteLine("Did not put in enough money");
                Console.ReadLine();
            }

            if (coins < canPriceOrange)


            {
                Console.WriteLine("Did not put in enough money");
                Console.ReadLine();
            }

            if (coins < canPriceLemon)


            {
                Console.WriteLine("Did not put in enough money");
                Console.ReadLine();
            }

            if (coins = canPriceGrape)


            {
                Console.WriteLine("You have just purchased a Grape soda ");
                Console.ReadLine();
            }

            if (coins = canPriceOrange)


            {
                Console.WriteLine("You have just purchased a Orange soda ");
                Console.ReadLine();
            }


            if (coins = canPriceLemon)


            {
                Console.WriteLine("You have just purchased a Lemon soda ");
                Console.ReadLine();
            }
        }
Пример #28
0
        public void AddQuarterToSelectedCoins()
        {
            Quarter quarter = new Quarter();

            selectedCoins.Add(quarter);
        }
Пример #29
0
        // Member Variables

        // Member Methods
        // Coin Builders
        public static Quarter Quarter()
        {
            Quarter quarter = new Quarter();

            return(quarter);
        }
Пример #30
0
        public static void CoinPrompt(string currentCoin, List <Coin> coins, List <Coin> insertedCoins)
        {
            UserInterface.DisplayCoinWallet(coins);
            UserInterface.AskForNextCoin(currentCoin);
            int coinsEntered;
            int counter = 0;

            switch (currentCoin)
            {
            case "quarters":
                coinsEntered = UserInterface.GetIntInput();
                for (int i = 0; i < coins.Count; i++)
                {
                    if (counter == (coinsEntered))
                    {
                        break;
                    }
                    if (coins[i].name == "quarter")
                    {
                        Quarter quarter = new Quarter();
                        insertedCoins.Add(quarter);
                        coins.RemoveAt(i);
                        counter++;
                        i--;
                    }
                }
                UserInterface.DisplayCoinInserted(counter, currentCoin);
                break;

            case "dimes":
                coinsEntered = UserInterface.GetIntInput();
                for (int i = 0; i < coins.Count; i++)
                {
                    if (counter == coinsEntered)
                    {
                        break;
                    }
                    if (coins[i].name == "dime")
                    {
                        Dime dime = new Dime();
                        insertedCoins.Add(dime);
                        coins.RemoveAt(i);
                        counter++;
                        i--;
                    }
                }
                UserInterface.DisplayCoinInserted(counter, currentCoin);
                break;

            case "nickels":
                coinsEntered = UserInterface.GetIntInput();
                for (int i = 0; i < coins.Count; i++)
                {
                    if (counter == coinsEntered)
                    {
                        break;
                    }
                    if (coins[i].name == "nickel")
                    {
                        Nickel nickel = new Nickel();
                        insertedCoins.Add(nickel);
                        coins.RemoveAt(i);
                        counter++;
                        i--;
                    }
                }
                UserInterface.DisplayCoinInserted(counter, currentCoin);
                break;

            case "pennies":
                coinsEntered = UserInterface.GetIntInput();
                for (int i = 0; i < coins.Count; i++)
                {
                    if (counter == coinsEntered)
                    {
                        break;
                    }
                    if (coins[i].name == "penny")
                    {
                        Penny penny = new Penny();
                        insertedCoins.Add(penny);
                        coins.RemoveAt(i);
                        counter++;
                        i--;
                    }
                }
                UserInterface.DisplayCoinInserted(counter, currentCoin);
                break;

            default:
                break;
            }
        }