示例#1
0
        public void Transfer(decimal amount, Account toAccount)
        {
            if (amount > _balance)
            {
                throw new Exception(String.Format("Cannot transfer ${0}. The available balance is ${1}.", amount, _balance));
            }

            _balance -= amount;
            toAccount.Balance += amount;
        }
        static void Main(string[] args)
        {
            var differentAccounts = new Account[]
            {
                new Loan(new Customer(true), 700m, 17.5m, 6),
                new Deposit(new Customer(false), 1500m, 12.3m, 13),
                new Mortgage(new Customer(true), 600m, 14m, 14)
            };

            foreach (var item in differentAccounts)
            {
                Console.WriteLine(item.GetType() + " " + item.CalculateInterestForAPeriodOfMonths());
            }
        }