public MainWindow()
 {
     InitializeComponent();
     repo = new CurrencyRepo()
     {
         Coins = new List <ICoin> {
             new Penny()
         }
     };
 }
Пример #2
0
        public ICurrencyRepo MakeChange(double Amount)
        {
            DollarCoin dollarCoin = new DollarCoin();
            HalfDollar halfDollar = new HalfDollar();
            Quarter    quarter    = new Quarter();
            Dime       dime       = new Dime();
            Nickel     nickel     = new Nickel();
            Penny      penny      = new Penny();

            cr = new CurrencyRepo();
            while (Amount > 0)
            {
                if (Math.Round(Amount, 2) - Math.Round(dollarCoin.MonetaryValue, 2) >= 0)
                {
                    Amount = Math.Round(Amount, 2) - Math.Round(dollarCoin.MonetaryValue, 2);
                    cr.AddCoin(dollarCoin);
                }

                else if (Math.Round(Amount, 2) - Math.Round(halfDollar.MonetaryValue, 2) >= 0)
                {
                    Amount = Math.Round(Amount, 2) - Math.Round(halfDollar.MonetaryValue, 2);
                    cr.AddCoin(halfDollar);
                }

                else if (Math.Round(Amount, 2) - Math.Round(quarter.MonetaryValue, 2) >= 0)
                {
                    Amount = Math.Round(Amount, 2) - Math.Round(quarter.MonetaryValue, 2);
                    cr.AddCoin(quarter);
                }

                else if (Math.Round(Amount, 2) - Math.Round(dime.MonetaryValue, 2) >= 0)
                {
                    Amount = Math.Round(Amount, 2) - Math.Round(dime.MonetaryValue, 2);
                    cr.AddCoin(dime);
                }
                else if (Math.Round(Amount, 2) - Math.Round(nickel.MonetaryValue, 2) >= 0)
                {
                    Amount = Math.Round(Amount, 2) - Math.Round(nickel.MonetaryValue, 2);
                    cr.AddCoin(nickel);
                }
                else if (Math.Round(Amount, 2) - Math.Round(penny.MonetaryValue, 2) >= 0)
                {
                    Amount = Math.Round(Amount, 2) - Math.Round(penny.MonetaryValue, 2);
                    cr.AddCoin(penny);
                }
                else
                {
                    Amount = 0;
                }
            }
            return(cr);
        }
Пример #3
0
 public WindowMakeChange(CurrencyRepo repo)
 {
     this.repo = repo;
     InitializeComponent();
 }