コード例 #1
0
        static void Main(string[] args)
        {
            Savings newSav = new Savings();

            newSav.number = "Sav001";
            newSav.name   = "Big Savings";
            newSav.Deposit(4000);
            newSav.changeRate(-0.04);

            Checking check1 = new Checking();

            check1.Deposit(10000000.00m);
            check1.Pay(1002, 354.34m);
            check1.name   = "Check001";
            check1.number = "Chk0034";


            MoneyMarket mmAcct = new MoneyMarket();

            mmAcct.number = "1003";
            mmAcct.changeRate(0.05);
            mmAcct.name = "Test MM";
            mmAcct.Deposit(500);
            mmAcct.intPay(45);

            Account[] Accounts = { mmAcct, newSav, check1 };

            foreach (var account in Accounts)
            {
                Console.WriteLine(account.Print());
            }

            //Savings saveAcct = new Savings();
            //saveAcct.number = "1002";
            //saveAcct.name = "Test Savings";
            //saveAcct.intRate = 0.05;



            //saveAcct.Deposit(200);
            //saveAcct.Withdraw(100);

            //decimal toBePaid = saveAcct.intCalc(6);
            //saveAcct.PayInterest(toBePaid);

            //decimal savBal = saveAcct.GetBalance();
            //Console.WriteLine($"Save Balance is {savBal}");

            //Account acct = new Account();
            //acct.number = "1001";
            //acct.name = "Test Account";
            //acct.Deposit(20);
            //acct.Withdraw(10);


            //decimal balance = acct.GetBalance();
            //Console.WriteLine($"Account Balance is {balance} (should be 10)");

            //acct.Deposit(-10);
            //balance = acct.GetBalance();
            //Console.WriteLine($"Account Balance is {balance} (should be 10)");

            //acct.Withdraw(-10);
            //balance = acct.GetBalance();
            //Console.WriteLine($"Account Balance is {balance} (should be 10)");

            //acct.Withdraw(100);
            //balance = acct.GetBalance();
            //Console.WriteLine($"Account Balance is {balance} (should be 10)");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Savings sav1 = new Savings();

            sav1.Number = "SAV001";
            sav1.Name   = "My savings account";
            sav1.ChangeRate(0.02);


            MoneyMarket MM = new MoneyMarket();

            MM.Number = "MM1001";
            MM.Name   = "MoneyMarket 1";
            MM.Deposit(100);
            MM.MMIntRate = 0.10;
            MM.PayInterest(12);

            Checking check1 = new Checking();

            check1.Number = "CHECK001";
            check1.Name   = "My checking account";
            check1.Deposit(100);
            check1.Pay(100, 20);


            Account[] accounts = new Account[] { sav1, MM, check1 }; //Example of Polymorphism

            foreach (Account acct in accounts)                       // Example of Polymorphism
            {
                Console.WriteLine(acct.Print());
            }


            /*
             * Savings sav = new Savings();
             * sav.Number = "1002";
             * sav.Name = "Savings 1";
             * sav.IntRate = 0.05;
             *
             * sav.Deposit(200);
             * sav.Withdraw(100);
             * decimal interestToBePaid = sav.CalcInterest(12);
             * sav.PayInterest(interestToBePaid);
             * decimal savbal = sav.GetBalance();
             * Console.WriteLine($"Savings balance is {savbal}");
             *
             *
             *
             * Account acct = new Account();
             * acct.Number = "1001";
             * acct.Name = "TestAccount";
             *
             * acct.Deposit(20);
             * acct.Withdraw(10);
             *
             * acct.GetBalance();
             * decimal balance = acct.GetBalance();
             * Console.WriteLine($"Account balance is {balance} (should be 10)");
             *
             * acct.Deposit(-10);
             * balance = acct.GetBalance();
             * Console.WriteLine($"Account balance is {balance} (should be 10)");
             *
             * acct.Withdraw(-10);
             * balance = acct.GetBalance();
             * Console.WriteLine($"Account balance is {balance} (should be 10)");
             *
             * acct.Withdraw(20);
             * balance = acct.GetBalance();
             * Console.WriteLine($"Account balance is {balance} (should be 10)");
             */
        }