예제 #1
0
        private String statementForAccount(Account a)
        {
            String s = "";
            string tranType = "";
            //Translate to pretty account type
            switch (a.getAccountType())
            {
                case Account.CHECKING:
                    s += "Checking Account\n";
                    break;
                case Account.SAVINGS:
                    s += "Savings Account\n";
                    break;
                case Account.MAXI_SAVINGS:
                    s += "Maxi Savings Account\n";
                    break;
            }

            //Now total up all the transactions
            double total = 0.0;
            foreach (Transaction t in a.transactions)
            {
                tranType = (t.tranType == Transaction.operation.Transfer ? "transfer" + (t.amount < 0 ? " from" : " to") : (t.tranType == Transaction.operation.Withdrawal ? "withdrawal" : "deposit"));
                s += "  " + tranType + " " + toDollars(t.amount) + "\n";
                total += t.amount;
            }
            s += "Total " + toDollars(total);
            return s;
        }
예제 #2
0
        private String statementForAccount(Account a)
        {
            //IS - StringBuilder is more efficient.
            StringBuilder s = new StringBuilder();

            //Translate to pretty account type
            switch (a.AccountType)
            {
                case AccountType.CHECKING:
                    s.Append("Checking Account\n");
                    break;
                case AccountType.SAVINGS:
                    s.Append("Savings Account\n");
                    break;
                case AccountType.MAXI_SAVINGS:
                    s.Append("Maxi Savings Account\n");
                    break;
            }

            //Now total up all the transactions
            double total = 0.0;
            //Linq foreach is easier to read/maintain.
            a.Transactions.ForEach(x => {
                s.Append(string.Format(" {0} {1}\n", (x.Amount < 0 ? " withdrawal" : " deposit"), toDollars(x.Amount)));
                total += x.Amount;
            });

            s.Append(string.Format("Total {0}", toDollars(total)));
            return s.ToString();
        }
예제 #3
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));
 }
예제 #4
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;
        }
예제 #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);
            }
        }
예제 #6
0
 public Customer openAccount(Account account)
 {
     accounts.Add(account);
     return this;
 }
예제 #7
0
        public Account transferAccounts(Account from)
        {
            Account to = new Account(from.AccountType);

            to.AccountType = from.AccountType;
            to.Transactions.AddRange(from.Transactions);

            return to;
        }
예제 #8
0
        private String statementForAccount(Account a)
        {
            String s = "";

            //Translate to pretty account type
            switch (a.getAccountType())
            {
                case AccountType.Checking:
                    s += "Checking Account\n";
                    break;
                case AccountType.Savings:
                    s += "Savings Account\n";
                    break;
                case AccountType.MaxiSavings:
                    s += "Maxi Savings Account\n";
                    break;
            }

            //Now total up all the transactions
            double total = 0.0;
            foreach (Transaction t in a.transactions)
            {
                s += "  " + (t.Amount < 0 ? "withdrawal" : "deposit") + " " + toDollars(t.Amount) + "\n";
                total += t.Amount;
            }
            s += "Total " + toDollars(total);
            return s;
        }