Transfer() public method

public Transfer ( decimal amount, Account toAccount ) : void
amount decimal
toAccount Account
return void
Beispiel #1
0
        static void Main(string[] args)
        {
            var sav1 = new Savings(0.12, "My Savings");

            sav1.Deposit(1000);
            sav1.Print();
            sav1.PayInterest(1);
            sav1.Print();

            var sav2 = new Savings2(0.12, "My Composite Savings");

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

            Savings2.Transfer(100, sav1, sav2);

            var acct1 = new Account();
            var acct2 = new Account("My Checking");

            Account.Deposit(500, acct1);
            acct1.Print();
            acct2.Print();
            acct2.Deposit(1000);
            acct2.Withdraw(2000);
            acct2.Print();

            try {
                acct2.Withdraw(5000);
                acct2.Print();
                acct2.Deposit(-200);
                acct2.Print();
                acct2.Withdraw(-200);
                acct2.Print();
            } catch (InsufficientFundsException ex) {
                Console.WriteLine($"Insufficient Funds: Acct: {ex.AccountId}, Amt: {ex.AmountToWithdraw}, Bal: {ex.Balance}");
            } catch (DivideByZeroException ex) {
                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!");
            }
            acct2.Print();
            acct1.Print();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var act100 = new Account();

            act100.Deposit(-100);
            try
            {
                act100.Withdrawal(12000);
            }
            catch (InsufficientFundsException ex) { }

            catch (DivideByZeroException ex) { throw; }

            catch (Exception ex) { }  //do this one last always since first exception that is true is thrown

            var sv1 = new Savings2();

            sv1.Deposit(2000);
            var cd10     = new CertificateOfDeposit(5000, 60);
            var accounts = new IBanking[] { sv1, cd10 };

            foreach (var acct in accounts)
            {
                Console.WriteLine($"Account balance is {acct.GetBalance()}"); //need to add composition method for CD for this to work
            }



            var sav1 = new Savings();

            sav1.Deposit(1000);
            sav1.PayInterest(3);


            var acct1 = new Account();

            acct1.Deposit(500);
            acct1.Withdrawal(200);
            acct1.Withdrawal(600);
            acct1.Deposit(-400);
            Console.WriteLine($"Balance is {acct1.Balance}");

            var acct2 = new Account();

            acct1.Transfer(1000, acct2);
            Console.WriteLine($"Balance is {acct1.Balance}");
            Console.WriteLine($"Balance is {acct2.Balance}");

            var cd1 = new CertificateOfDeposit(Amount: 1000, Months: 12);

            cd1.Deposit(1);
            cd1.Withdrawal(1);
            cd1.WithdrawlDate = DateTime.Now.AddDays(-1); //yesterday
            var funds = cd1.Withdrawal();                 //no parameters sine we will withdraw everything in acocunt
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var sav1 = new Savings(0.12, "My Savings");

            sav1.Deposit(1000);
            sav1.Print();
            sav1.PayInterest(1); // pay interest for one month
            sav1.Print();

            var sav2 = new Savings2(0.12, "My Composite Savings");  // Done with composite in stead of inherited class

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

            Savings2.Transfer(100, sav1, sav2);


            var acct1 = new Account();
            var acct2 = new Account("My Checking");

            try {
                Account.Deposit(500, acct1);
                acct1.Print();
                acct2.Print();
                acct2.Deposit(1000);
                acct2.Print();
                acct2.Withdraw(50);
                acct2.Print();
                acct2.Deposit(-200);
                acct2.Print();
                acct2.Withdraw(-200);
                acct2.Print();
            } catch (DivideByZeroException ex) {
                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!");
            }
            acct2.Print();
            acct1.Print();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var sav1 = new Savings(0.12, "My Savings");

            sav1.Deposit(1000);
            sav1.Print();
            var interest = sav1.CalculateInterest(1);

            sav1.PayInterest(1);
            sav1.Print();

            var sav2 = new Savings2(0.12, "My Composite Savings");

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

            var acct1 = new Account();
            var acct2 = new Account("My Checking");

            try {
                acct2.Print();
                acct2.Deposit(1000);
                acct2.Print();
                acct2.Withdraw(50);
                acct2.Print();
                acct2.Deposit(-200);
                acct2.Print();
                acct2.Withdraw(-200);
                acct2.Print();
            } 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!");
            }
            acct2.Print();
            acct1.Print();
        }
        static void Main(string[] args)
        {
            var acct1 = new Account();

            acct1.Deposit(500);
            acct1.Withdraw(200);
            acct1.Withdraw(600);
            acct1.Withdraw(-100);
            Console.WriteLine($"Balance is {acct1.Balance}");

            var acct2 = new Account();

            acct1.Transfer(1000, acct2);
            Console.WriteLine($"Balance is {acct1.Balance}");
            Console.WriteLine($"Balance is {acct2.Balance}");
        }
Beispiel #6
0
        // Run method pushed up to GitHub

        void TestAccount()
        {
            Account checking = new Account();

            checking.SetName("Checking 1");
            checking.Withdraw(100.00);
            checking.Deposit(50.00);
            checking.Deposit(-100.00);
            Console.WriteLine($"Account Nbr:{checking.getNumber()}, Name: {checking.GetName()}, balance is {checking.CheckBalance()}");
            Savings savings = new Savings("My Savings Account");

            savings.IntRate = 0.10;
            savings.Deposit(70.00);
            Console.WriteLine($"Account Nbr:{savings.getNumber()}, Name: {savings.GetName()}, balance is {savings.CheckBalance()}");

            savings.Transfer(30.00, checking);

            Console.WriteLine($"Account Nbr:{checking.getNumber()}, Name: {checking.GetName()}, balance is {checking.CheckBalance()}");
            Console.WriteLine($"Account Nbr:{savings.getNumber()}, Name: {savings.GetName()}, balance is {savings.CheckBalance()}");

            checking.Transfer(-10.00, savings);

            Console.WriteLine($"Account Nbr:{checking.getNumber()}, Name: {checking.GetName()}, balance is {checking.CheckBalance()}");
            Console.WriteLine($"Account Nbr:{savings.getNumber()}, Name: {savings.GetName()}, balance is {savings.CheckBalance()}");

            savings.Transfer(100.00, checking);

            Console.WriteLine($"Account Nbr:{checking.getNumber()}, Name: {checking.GetName()}, balance is {checking.CheckBalance()}");
            Console.WriteLine($"Account Nbr:{savings.getNumber()}, Name: {savings.GetName()}, balance is {savings.CheckBalance()}");

            savings.PayMonthlyInterest();

            Console.WriteLine($"Savings Nbr:{savings.getNumber()}, Name: {savings.GetName()}, balance is {savings.CheckBalance()}");

            Savings sav1 = new Savings("Greg's Savings with Interest", 0.05);
        }
Beispiel #7
0
 public static bool Transfer(double amount, Savings2 FromAccount, Savings2 ToAccount)
 {
     return(Account.Transfer(amount, FromAccount.Account, ToAccount.Account));
 }
 public bool Transfer(decimal amount, Account toAccount)
 {
     return(account.Transfer(amount, toAccount));
 }