Exemplo n.º 1
0
        // 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);
        }
Exemplo n.º 2
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));
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 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));
 }
Exemplo n.º 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);
            }
        }