示例#1
0
        static void Main(string[] args)
        {
            var sav1 = new Saving("My Savings");
            var sav2 = new Saving(.12, "New Account");

            sav2.Deposit(1000);
            sav2.print();
            sav2.PayInterest(1);
            sav2.print();

            var sav3 = new SavingComp(0.12, "My Composite Savings");

            sav3.Print();
            SavingComp.Transfer(500, sav2, sav3);
            sav3.Print();

            var acct1 = new Account();

            acct1.print();
            var acct2 = new Account("My checking");

            acct2.print();
            acct2.Deposit(1000);
            acct2.print();
            try {
                acct2.Withdraw(5000);
                acct2.print();
                acct2.Withdraw(-200);
                acct2.print();
                acct2.Deposit(-200);
                acct2.print();
            }
            catch (InsufficientFundsException ex) {
                Console.WriteLine($"Insufficient Funds {ex.AccountId}: Account Withdrawn is {ex.AmountToWithdraw}. The balance is {ex.Balance}");
            }
            catch (DivideByZeroException) {
                Console.WriteLine("Attempted to divide by zero");
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
            var success = Account.Transfer(200, acct2, acct1);

            if (success)
            {
                Console.WriteLine("the transfer worked!");
            }
            else
            {
                Console.WriteLine("The transfer failed!");
            }
        }
示例#2
0
 public static bool Transfer(double amount, Account FromAccount, SavingComp ToAccount)
 {
     return(Account.Transfer(amount, FromAccount, ToAccount.Account));
 }
示例#3
0
 public static bool Transfer(double amount, SavingComp sc1, SavingComp sc2)
 {
     return(Account.Transfer(amount, sc1.Account, sc2.Account));
 }