// transfer funds between two accounts belonging to same customer - returns true if successful
        public bool transferFundsBetweenAccounts(double amount, Account accountOut, Account accountIn)
        {
            bool result = false;

            // first check whether amount being transferred is positive
            if (amount <= 0)
            {
                result = false;
            }
            else
            {
                // check whether customer has possession of accountOut/accountIn and whether there are sufficient funds in accountOut
                bool accountOutExists = false;
                bool accountOutBalPos = false;
                bool accountInExists  = false;
                foreach (Account a in accounts)
                {
                    if (a.getAccountID() == accountOut.getAccountID())
                    {
                        accountOutExists = true;
                        break;
                    }
                }
                if (accountOutExists == true)
                {
                    // check whether account has sufficient funds
                    if (accountOut.accountBalance() >= amount)
                    {
                        accountOutBalPos = true;
                    }
                    else
                    {
                        accountOutBalPos = false;
                        // should include method for imposing fee on customer for Insufficient Funds, though ideally using false result
                    }
                }
                foreach (Account a in accounts)
                {
                    if (a.getAccountID() == accountIn.getAccountID())
                    {
                        accountInExists = true;
                        break;
                    }
                }

                // if outgoing account has positive balance AND ingoing account exists, proceed with transfer
                if ((accountOutBalPos == true) && (accountInExists == true))
                {
                    accountOut.withdraw(amount);
                    accountIn.deposit(amount);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
 public void transfer(double amount, Account from, Account to)
 {   
     if(!accounts.Contains(from))
         throw new ArgumentException("Source account does not belong to the customer");
     if (!accounts.Contains(to))
         throw new ArgumentException("Target account does not belong to the customer");
     to.deposit(from.withdraw(amount));
 }
        public Customer transfer(Account fromAccount, Account toAccount, double transferAmoumt)
        {
            //in statement transfer will appear as withdraw for one account and deposit for another
            //TO DO It should be different
            fromAccount.withdraw(transferAmoumt, true);
            toAccount.deposit(transferAmoumt, true);

            return this;
        }
Exemple #4
0
 public void transfer(double amount, Account from, Account to)
 {
     if (!accounts.Contains(from))
     {
         throw new ArgumentException("Source account does not belong to the customer");
     }
     if (!accounts.Contains(to))
     {
         throw new ArgumentException("Target account does not belong to the customer");
     }
     to.deposit(from.withdraw(amount));
 }
Exemple #5
0
        public void TransferFunds(Account sourceAccount, Account targetAccount, double amount)
        {
            if (sourceAccount.Balance() > amount)
            {
                sourceAccount.withdraw(amount);
                targetAccount.deposit(amount);
            }
            else
            {
                String msg = GetInsufficientFundsMessage(sourceAccount.Balance(), amount);

                throw new Exception(msg);
            }
        }