From ceb482c9a234cc8d8810ef65c1cbb34f3c664f7c Mon Sep 17 00:00:00 2001 From: Connor Hammond Date: Mon, 1 Feb 2016 09:58:38 -0500 Subject: [PATCH 1/6] Refactors original, new features still to be added --- abcbank/account.py | 62 +++++++++++++++++++++----------------- abcbank/bank.py | 20 +++++++----- abcbank/customer.py | 36 +++++++++++----------- abcbank/transaction.py | 5 +-- bank_tests.py | 39 ++++++++++++++++++++++++ customer_tests.py | 49 ++++++++++++++++++++++++++++++ tests/__init__.py | 0 tests/bank_tests.py | 38 ----------------------- tests/customer_tests.py | 36 ---------------------- tests/transaction_tests.py | 8 ----- transaction_tests.py | 21 +++++++++++++ 11 files changed, 178 insertions(+), 136 deletions(-) create mode 100644 bank_tests.py create mode 100644 customer_tests.py delete mode 100644 tests/__init__.py delete mode 100644 tests/bank_tests.py delete mode 100644 tests/customer_tests.py delete mode 100644 tests/transaction_tests.py create mode 100644 transaction_tests.py diff --git a/abcbank/account.py b/abcbank/account.py index e010009..9b15b54 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,43 +1,51 @@ from abcbank.transaction import Transaction -CHECKING = 0 -SAVINGS = 1 -MAXI_SAVINGS = 2 - - class Account: def __init__(self, accountType): self.accountType = accountType self.transactions = [] + self.balance = 0 def deposit(self, amount): - if (amount <= 0): - raise ValueError("amount must be greater than zero") - else: - self.transactions.append(Transaction(amount)) + if not amount > 0: + raise ValueError("Must enter an amount greater than zero") + new_transaction = Transaction(amount,'deposit') + self.balance += amount + self.transactions.append(new_transaction) def withdraw(self, amount): - if (amount <= 0): - raise ValueError("amount must be greater than zero") + if not amount > 0: + raise ValueError("Must enter an amount greater than zero") + if not self.balance >= amount: + raise ValueError("Insufficient Funds") else: - self.transactions.append(Transaction(-amount)) + new_transaction = Transaction(amount,'withdrawl') + self.balance -= amount + self.transactions.append(new_transaction) + + def sumTransactions(self, checkAllTransactions=True): + return sum([t.amount for t in self.transactions]) def interestEarned(self): - amount = self.sumTransactions() - if self.accountType == SAVINGS: - if (amount <= 1000): - return amount * 0.001 + default_interest = self.balance * 0.01 + second_tier_interest = self.balance * 0.02 + + if self.accountType == 'CHECKING': + return default_interest + + elif self.accountType == 'SAVINGS': + if self.balance <= 1000.0: + return default_interest else: - return 1 + (amount - 1000) * 0.002 - if self.accountType == MAXI_SAVINGS: - if (amount <= 1000): - return amount * 0.02 - elif (amount <= 2000): - return 20 + (amount - 1000) * 0.05 + return second_tier_interest + + elif self.accountType == 'MAXI_SAVINGS': + if self.balance <= 1000.0: + return second_tier_interest + elif self.balance <= 2000.0: + return self.balance * 0.05 else: - return 70 + (amount - 2000) * 0.1 - else: - return amount * 0.001 + return self.balance * 0.1 - def sumTransactions(self, checkAllTransactions=True): - return sum([t.amount for t in self.transactions]) \ No newline at end of file + + \ No newline at end of file diff --git a/abcbank/bank.py b/abcbank/bank.py index 44711fe..c28d2f2 100644 --- a/abcbank/bank.py +++ b/abcbank/bank.py @@ -1,25 +1,31 @@ +from .customer import Customer + class Bank: def __init__(self): self.customers = [] - def addCustomer(self, customer): - self.customers.append(customer) + def addCustomer(self, customer_name): + new_customer = Customer(customer_name) + self.customers.append(new_customer) + return new_customer + def customerSummary(self): summary = "Customer Summary" for customer in self.customers: - summary = summary + "\n - " + customer.name + " (" + self._format(customer.numAccs(), "account") + ")" + summary += "\n - " + customer.name + " (" + self._format(customer.numAccs(), "account") + ")" return summary + def _format(self, number, word): return str(number) + " " + (word if (number == 1) else word + "s") + def totalInterestPaid(self): total = 0 for c in self.customers: total += c.totalInterestEarned() return total + def getFirstCustomer(self): - try: - self.customers = None + if self.customers: return self.customers[0].name - except Exception as e: - print(e) + else: return "Error" \ No newline at end of file diff --git a/abcbank/customer.py b/abcbank/customer.py index 7cfd62a..6c4e6c6 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -1,4 +1,4 @@ -from account import CHECKING, SAVINGS, MAXI_SAVINGS +from .account import Account class Customer: @@ -6,16 +6,24 @@ def __init__(self, name): self.name = name self.accounts = [] - def openAccount(self, account): - self.accounts.append(account) - return self - + def openAccount(self, account_type): + is_valid = ['CHECKING','SAVINGS','MAXI_SAVINGS'] + if account_type in is_valid: + new_account = Account(account_type) + self.accounts.append(new_account) + return new_account + else: + raise ValueError("Invalid Account Type") + def numAccs(self): return len(self.accounts) def totalInterestEarned(self): return sum([a.interestEarned() for a in self.accounts]) + def totalAssets(self): + return "Total Assets: " + _toDollars(sum([a.balance for a in self.accounts])) + # This method gets a statement def getStatement(self): # JIRA-123 Change by Joe Bloggs 29/7/1988 start @@ -25,30 +33,22 @@ def getStatement(self): statement = "Statement for %s" % self.name for account in self.accounts: statement = statement + self.statementForAccount(account) - statement = statement + "\n\nTotal In All Accounts " + _toDollars(totalAcrossAllAccounts) + statement += "\n\nTotal In All Accounts " + _toDollars(totalAcrossAllAccounts) return statement def statementForAccount(self, account): accountType = "\n\n\n" - if account.accountType == CHECKING: + if account.accountType == 'CHECKING': accountType = "\n\nChecking Account\n" - if account.accountType == SAVINGS: + if account.accountType == 'SAVINGS': accountType = "\n\nSavings Account\n" - if account.accountType == MAXI_SAVINGS: + if account.accountType == 'MAXI_SAVINGS': accountType = "\n\nMaxi Savings Account\n" - transactionSummary = [self.withdrawalOrDepositText(t) + " " + _toDollars(abs(t.amount)) - for t in account.transactions] + transactionSummary = [self.action + " " + _toDollars(abs(t.amount)) for t in account.transactions] transactionSummary = " " + "\n ".join(transactionSummary) + "\n" totalSummary = "Total " + _toDollars(sum([t.amount for t in account.transactions])) return accountType + transactionSummary + totalSummary - def withdrawalOrDepositText(self, transaction): - if transaction.amount < 0: - return "withdrawal" - elif transaction.amount > 0: - return "deposit" - else: - return "N/A" def _toDollars(number): diff --git a/abcbank/transaction.py b/abcbank/transaction.py index 8e5b5ad..36b8228 100644 --- a/abcbank/transaction.py +++ b/abcbank/transaction.py @@ -2,6 +2,7 @@ class Transaction: - def __init__(self, amount): + def __init__(self,amount,action): self.amount = amount - self.transactionDate = datetime.now() \ No newline at end of file + self.transactionDate = datetime.now() + self.action = action \ No newline at end of file diff --git a/bank_tests.py b/bank_tests.py new file mode 100644 index 0000000..0180a5d --- /dev/null +++ b/bank_tests.py @@ -0,0 +1,39 @@ +from nose.tools import assert_equals +from abcbank.account import Account +from abcbank.bank import Bank +from abcbank.customer import Customer +from abcbank.transaction import Transaction + + +def test_customer_summary(): + bank = Bank() + john = bank.addCustomer('John') + john_new_checking = john.openAccount('CHECKING') + assert_equals(bank.customerSummary(),"Customer Summary\n - John (1 account)") + +def test_checking_account(): + bank = Bank() + bill = bank.addCustomer("Bill") + bill_new_checking = bill.openAccount('CHECKING') + bill_new_checking.deposit(100.00) + assert_equals(bank.totalInterestPaid(), 1.0) + +def test_savings_account(): + bank = Bank() + bill = bank.addCustomer("Bill") + bill_new_savings = bill.openAccount('SAVINGS') + bill_new_savings.deposit(1500.0) + assert_equals(bank.totalInterestPaid(), 30.0) + +def test_maxi_savings_account(): + bank = Bank() + bill = bank.addCustomer("Bill") + bill_new_maxi = bill.openAccount('MAXI_SAVINGS') + bill_new_maxi.deposit(3000.0) + assert_equals(bank.totalInterestPaid(), 300.0) + +if __name__ == '__main__': + test_customer_summary() + test_checking_account() + test_savings_account() + test_maxi_savings_account() \ No newline at end of file diff --git a/customer_tests.py b/customer_tests.py new file mode 100644 index 0000000..c6c0901 --- /dev/null +++ b/customer_tests.py @@ -0,0 +1,49 @@ +from nose.tools import assert_equals, nottest +from abcbank.bank import Bank +from abcbank.account import Account +from abcbank.customer import Customer +from abcbank.transaction import Transaction + + +def test_statement(): + bank = Bank() + henry = bank.addCustomer("Henry") + henry_checking=henry.openAccount('CHECKING') + henry_savings = henry.openAccount('SAVINGS') + henry_checkings.deposit(100.0) + henry_savings.deposit(4000.0) + henry_savings.withdraw(200.0) + assert_equals(henry.getStatement(), + "Statement for Henry" + + "\n\nChecking Account\n deposit $100.00\nTotal $100.00" + + "\n\nSavings Account\n deposit $4000.00\n withdrawal $200.00\nTotal $3800.00" + + "\n\nTotal In All Accounts $3900.00") + + +def test_oneAccount(): + bank = Bank() + oscar = bank.addCustomer("Oscar") + oscar_savings = oscar.openAccount('SAVINGS') + assert_equals(oscar.numAccs(), 1) + +def test_twoAccounts(): + bank = Bank() + oscar = bank.addCustomer("Oscar") + oscar_savings = oscar.openAccount('SAVINGS') + oscar_checking = oscar.openAccount('CHECKING') + assert_equals(oscar.numAccs(), 2) + +@nottest +def test_threeAccounts(): + bank = Bank() + oscar = bank.addCustomer("Oscar") + oscar_savings = oscar.openAccount('SAVINGS') + oscar_checking = oscar.openAccount('CHECKING') + oscar_checking = oscar.openAccount('MAXI_SAVINGS') + assert_equals(oscar.numAccs(), 3) + +if __name__ == '__main__': + test_oneAccount() + test_twoAccounts() + test_threeAccounts() + diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/bank_tests.py b/tests/bank_tests.py deleted file mode 100644 index 6de98db..0000000 --- a/tests/bank_tests.py +++ /dev/null @@ -1,38 +0,0 @@ -from nose.tools import assert_equals - -from account import Account, CHECKING, MAXI_SAVINGS, SAVINGS -from bank import Bank -from customer import Customer - - -def test_customer_summary(): - bank = Bank() - john = Customer("John").openAccount(Account(CHECKING)) - bank.addCustomer(john) - assert_equals(bank.customerSummary(), - "Customer Summary\n - John (1 account)") - - -def test_checking_account(): - bank = Bank() - checkingAccount = Account(CHECKING) - bill = Customer("Bill").openAccount(checkingAccount) - bank.addCustomer(bill) - checkingAccount.deposit(100.0) - assert_equals(bank.totalInterestPaid(), 0.1) - - -def test_savings_account(): - bank = Bank() - checkingAccount = Account(SAVINGS) - bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) - checkingAccount.deposit(1500.0) - assert_equals(bank.totalInterestPaid(), 2.0) - - -def test_maxi_savings_account(): - bank = Bank() - checkingAccount = Account(MAXI_SAVINGS) - bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) - checkingAccount.deposit(3000.0) - assert_equals(bank.totalInterestPaid(), 170.0) \ No newline at end of file diff --git a/tests/customer_tests.py b/tests/customer_tests.py deleted file mode 100644 index 0211a4f..0000000 --- a/tests/customer_tests.py +++ /dev/null @@ -1,36 +0,0 @@ -from nose.tools import assert_equals, nottest - -from account import Account, CHECKING, SAVINGS -from customer import Customer - - -def test_statement(): - checkingAccount = Account(CHECKING) - savingsAccount = Account(SAVINGS) - henry = Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount) - checkingAccount.deposit(100.0) - savingsAccount.deposit(4000.0) - savingsAccount.withdraw(200.0) - assert_equals(henry.getStatement(), - "Statement for Henry" + - "\n\nChecking Account\n deposit $100.00\nTotal $100.00" + - "\n\nSavings Account\n deposit $4000.00\n withdrawal $200.00\nTotal $3800.00" + - "\n\nTotal In All Accounts $3900.00") - - -def test_oneAccount(): - oscar = Customer("Oscar").openAccount(Account(SAVINGS)) - assert_equals(oscar.numAccs(), 1) - - -def test_twoAccounts(): - oscar = Customer("Oscar").openAccount(Account(SAVINGS)) - oscar.openAccount(Account(CHECKING)) - assert_equals(oscar.numAccs(), 2) - - -@nottest -def test_threeAccounts(): - oscar = Customer("Oscar").openAccount(Account(SAVINGS)) - oscar.openAccount(Account(CHECKING)) - assert_equals(oscar.numAccs(), 3) \ No newline at end of file diff --git a/tests/transaction_tests.py b/tests/transaction_tests.py deleted file mode 100644 index 62caa8a..0000000 --- a/tests/transaction_tests.py +++ /dev/null @@ -1,8 +0,0 @@ -from nose.tools import assert_is_instance - -from transaction import Transaction - - -def test_type(): - t = Transaction(5) - assert_is_instance(t, Transaction, "correct type") \ No newline at end of file diff --git a/transaction_tests.py b/transaction_tests.py new file mode 100644 index 0000000..cebdd19 --- /dev/null +++ b/transaction_tests.py @@ -0,0 +1,21 @@ +from nose.tools import assert_is_instance,assert_equal +from abcbank.account import Account +from abcbank.customer import Customer +from abcbank.transaction import Transaction +from abcbank.bank import Bank + + +def test_withdrawal(): + t = Transaction(5,'withdrawal') + assert_is_instance(t, Transaction) + assert_equal(t.action, 'withdrawal') + assert_equal(t.amount, 5) + +def test_deposit(): + t = Transaction(5,'deposit') + assert_is_instance(t, Transaction) + assert_equal(t.action, 'deposit') + +if __name__ == '__main__': + test_withdrawal() + test_deposit() From e18a305033efe317750dff1028d29df19b944e60 Mon Sep 17 00:00:00 2001 From: Connor Hammond Date: Mon, 1 Feb 2016 10:30:38 -0500 Subject: [PATCH 2/6] Fixed interest rate issue --- abcbank/account.py | 19 +++++++++---------- bank_tests.py | 6 +++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index 9b15b54..3932481 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -27,25 +27,24 @@ def sumTransactions(self, checkAllTransactions=True): return sum([t.amount for t in self.transactions]) def interestEarned(self): - default_interest = self.balance * 0.01 - second_tier_interest = self.balance * 0.02 + default_interest = self.balance * 0.001 + second_tier_interest = self.balance * 0.002 if self.accountType == 'CHECKING': return default_interest elif self.accountType == 'SAVINGS': - if self.balance <= 1000.0: - return default_interest + if self.balance <= 1000: + return default_interest else: - return second_tier_interest + return 1 + (self.balance - 1000) * 0.002 elif self.accountType == 'MAXI_SAVINGS': - if self.balance <= 1000.0: + if self.balance <= 1000: return second_tier_interest - elif self.balance <= 2000.0: - return self.balance * 0.05 + elif self.balance <= 2000: + return 20 + (self.balance - 1000) * 0.05 else: - return self.balance * 0.1 - + return 70 + (self.balance - 2000) * 0.1 \ No newline at end of file diff --git a/bank_tests.py b/bank_tests.py index 0180a5d..82e96a7 100644 --- a/bank_tests.py +++ b/bank_tests.py @@ -16,21 +16,21 @@ def test_checking_account(): bill = bank.addCustomer("Bill") bill_new_checking = bill.openAccount('CHECKING') bill_new_checking.deposit(100.00) - assert_equals(bank.totalInterestPaid(), 1.0) + assert_equals(bank.totalInterestPaid(), .1) def test_savings_account(): bank = Bank() bill = bank.addCustomer("Bill") bill_new_savings = bill.openAccount('SAVINGS') bill_new_savings.deposit(1500.0) - assert_equals(bank.totalInterestPaid(), 30.0) + assert_equals(bank.totalInterestPaid(), 2.0) def test_maxi_savings_account(): bank = Bank() bill = bank.addCustomer("Bill") bill_new_maxi = bill.openAccount('MAXI_SAVINGS') bill_new_maxi.deposit(3000.0) - assert_equals(bank.totalInterestPaid(), 300.0) + assert_equals(bank.totalInterestPaid(), 170.0) if __name__ == '__main__': test_customer_summary() From b9450508b62ac2880e8f0c67b5407db2e344fd9c Mon Sep 17 00:00:00 2001 From: Connor Hammond Date: Mon, 1 Feb 2016 10:54:55 -0500 Subject: [PATCH 3/6] Added ability for customer to transfer in between accounts; amended Maxi-Savings interest --- README.md | 2 +- abcbank/account.py | 20 +++++++++++--------- abcbank/customer.py | 9 ++++++--- abcbank/transaction.py | 3 ++- bank_tests.py | 12 +++++++++++- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 756dd11..d38965b 100644 --- a/README.md +++ b/README.md @@ -37,4 +37,4 @@ A dummy application for a bank; should provide various functions of a retail ban * A customer can transfer between their accounts * Change **Maxi-Savings accounts** to have an interest rate of 5% assuming no withdrawals in the past 10 days otherwise 0.1% -* Interest rates should accrue daily (incl. weekends), rates above are per-annum \ No newline at end of file +* Interest rates should accrue daily (incl. weekends), rates above are per-annum diff --git a/abcbank/account.py b/abcbank/account.py index 3932481..0009b3e 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -19,16 +19,16 @@ def withdraw(self, amount): if not self.balance >= amount: raise ValueError("Insufficient Funds") else: - new_transaction = Transaction(amount,'withdrawl') + new_transaction = Transaction(amount,'withdrawal') self.balance -= amount - self.transactions.append(new_transaction) + self.transactions.append(new_transaction) + def sumTransactions(self, checkAllTransactions=True): return sum([t.amount for t in self.transactions]) def interestEarned(self): default_interest = self.balance * 0.001 - second_tier_interest = self.balance * 0.002 if self.accountType == 'CHECKING': return default_interest @@ -40,11 +40,13 @@ def interestEarned(self): return 1 + (self.balance - 1000) * 0.002 elif self.accountType == 'MAXI_SAVINGS': - if self.balance <= 1000: - return second_tier_interest - elif self.balance <= 2000: - return 20 + (self.balance - 1000) * 0.05 + recentWithdrawal = False + for t in self.transactions: + if t.action == "withdrawal" and (datetime.now - t.transactionDate).days < 10: + recentWithdrawal = True + if recentWithdrawal: + return default_interest else: - return 70 + (self.balance - 2000) * 0.1 + return self.balance * 0.05 + - \ No newline at end of file diff --git a/abcbank/customer.py b/abcbank/customer.py index 6c4e6c6..90d8161 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -49,7 +49,10 @@ def statementForAccount(self, account): totalSummary = "Total " + _toDollars(sum([t.amount for t in account.transactions])) return accountType + transactionSummary + totalSummary + def makeTransfer(self,amount,account_to,account_from): + deposit_to = account_to.deposit(amount) + withdraw_from = account_from.withdraw(amount) + return self.get_statement() - -def _toDollars(number): - return "${:1.2f}".format(number) + def _toDollars(number): + return "${:1.2f}".format(number) diff --git a/abcbank/transaction.py b/abcbank/transaction.py index 36b8228..1f8536a 100644 --- a/abcbank/transaction.py +++ b/abcbank/transaction.py @@ -5,4 +5,5 @@ class Transaction: def __init__(self,amount,action): self.amount = amount self.transactionDate = datetime.now() - self.action = action \ No newline at end of file + self.action = action + \ No newline at end of file diff --git a/bank_tests.py b/bank_tests.py index 82e96a7..905f5f9 100644 --- a/bank_tests.py +++ b/bank_tests.py @@ -30,7 +30,17 @@ def test_maxi_savings_account(): bill = bank.addCustomer("Bill") bill_new_maxi = bill.openAccount('MAXI_SAVINGS') bill_new_maxi.deposit(3000.0) - assert_equals(bank.totalInterestPaid(), 170.0) + +def test_transfer(): + bank = Bank() + bill = bank.addCustomer("Bill") + bill_savings = bill.openAccount('SAVINGS') + bill_checking = bill.openAccount('CHECKING') + bill_savings.deposit(200.0) + bill_checking.deposit(100.0) + bill.transfer(50.0,savings,checking) + assert_equals(bill_checking.balance,50.0) + assert_equals(bill_savings.balance,250.0) if __name__ == '__main__': test_customer_summary() From 5f5f83556ab46523d54e8f3d608f422a5e35dc9c Mon Sep 17 00:00:00 2001 From: Connor Hammond Date: Mon, 1 Feb 2016 13:43:32 -0500 Subject: [PATCH 4/6] Adds daily interest accrual --- abcbank/account.py | 43 +++++++++++++++++++++++++++++------------- abcbank/customer.py | 9 +++++---- abcbank/transaction.py | 2 +- bank_tests.py | 16 +++++++++------- 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index 0009b3e..1d6ea88 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,10 +1,15 @@ from abcbank.transaction import Transaction +import datetime +from datetime import datetime, timedelta class Account: def __init__(self, accountType): self.accountType = accountType + self.dateOpened = datetime.now() self.transactions = [] self.balance = 0 + self.account_age_in_days = (datetime.now() - self.dateOpened).days + def deposit(self, amount): if not amount > 0: @@ -27,26 +32,38 @@ def withdraw(self, amount): def sumTransactions(self, checkAllTransactions=True): return sum([t.amount for t in self.transactions]) - def interestEarned(self): - default_interest = self.balance * 0.001 - + def dailyInterestRate(self): + default_interest = self.balance * 0.001 / 356 if self.accountType == 'CHECKING': - return default_interest + interest = (default_interest) elif self.accountType == 'SAVINGS': if self.balance <= 1000: - return default_interest + interest = default_interest else: - return 1 + (self.balance - 1000) * 0.002 + interest = (1 + (self.balance - 1000) * 0.002) / 356 elif self.accountType == 'MAXI_SAVINGS': - recentWithdrawal = False for t in self.transactions: - if t.action == "withdrawal" and (datetime.now - t.transactionDate).days < 10: - recentWithdrawal = True - if recentWithdrawal: - return default_interest - else: - return self.balance * 0.05 + if t.action == "withdrawal" and (datetime.now() - t.transactionDate).days < 10: + interest = default_interest + else: + interest = self.balance * 0.05 / 356 + return interest + + def interestEarnedDaily(self): + interest = 0 + if self.account_age_in_days > 0: + for day in range(self.account_age_in_days-1): + interest += self.dailyInterestRate() + return interest + + def accrueInterest(self): + for day in range(self.account_age_in_days-1): + self.balance += self.accruedDailyInterest() * self.interestEarnedDaily + return self.balance + + + diff --git a/abcbank/customer.py b/abcbank/customer.py index 90d8161..ef7761f 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -44,7 +44,7 @@ def statementForAccount(self, account): accountType = "\n\nSavings Account\n" if account.accountType == 'MAXI_SAVINGS': accountType = "\n\nMaxi Savings Account\n" - transactionSummary = [self.action + " " + _toDollars(abs(t.amount)) for t in account.transactions] + transactionSummary = [t.action + " " + _toDollars(t.amount) for t in account.transactions] transactionSummary = " " + "\n ".join(transactionSummary) + "\n" totalSummary = "Total " + _toDollars(sum([t.amount for t in account.transactions])) return accountType + transactionSummary + totalSummary @@ -52,7 +52,8 @@ def statementForAccount(self, account): def makeTransfer(self,amount,account_to,account_from): deposit_to = account_to.deposit(amount) withdraw_from = account_from.withdraw(amount) - return self.get_statement() + return self.getStatement() + +def _toDollars(number): + return "${:1.2f}".format(number) - def _toDollars(number): - return "${:1.2f}".format(number) diff --git a/abcbank/transaction.py b/abcbank/transaction.py index 1f8536a..0df6f1c 100644 --- a/abcbank/transaction.py +++ b/abcbank/transaction.py @@ -6,4 +6,4 @@ def __init__(self,amount,action): self.amount = amount self.transactionDate = datetime.now() self.action = action - \ No newline at end of file + diff --git a/bank_tests.py b/bank_tests.py index 905f5f9..9cfa785 100644 --- a/bank_tests.py +++ b/bank_tests.py @@ -21,9 +21,10 @@ def test_checking_account(): def test_savings_account(): bank = Bank() bill = bank.addCustomer("Bill") - bill_new_savings = bill.openAccount('SAVINGS') - bill_new_savings.deposit(1500.0) - assert_equals(bank.totalInterestPaid(), 2.0) + bill_new_maxi = bill.openAccount('MAXI_SAVINGS') + bill_new_maxi.deposit(1500.0) + bill_new_maxi.account_age_in_days = 10 + assert_equals(round(bill_new_maxi.interestEarnedDaily(),2),1.9) def test_maxi_savings_account(): bank = Bank() @@ -38,12 +39,13 @@ def test_transfer(): bill_checking = bill.openAccount('CHECKING') bill_savings.deposit(200.0) bill_checking.deposit(100.0) - bill.transfer(50.0,savings,checking) + bill.makeTransfer(50.0,bill_savings,bill_checking) assert_equals(bill_checking.balance,50.0) assert_equals(bill_savings.balance,250.0) if __name__ == '__main__': - test_customer_summary() - test_checking_account() + # test_customer_summary() + # test_checking_account() test_savings_account() - test_maxi_savings_account() \ No newline at end of file + # test_maxi_savings_account() + test_transfer() \ No newline at end of file From 856c428c290cee7ea77bc49495262ea500636f64 Mon Sep 17 00:00:00 2001 From: Connor Hammond Date: Mon, 1 Feb 2016 13:54:21 -0500 Subject: [PATCH 5/6] import tweak --- abcbank/account.py | 1 - abcbank/bank.py | 2 +- abcbank/customer.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index 1d6ea88..739b93c 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,5 +1,4 @@ from abcbank.transaction import Transaction -import datetime from datetime import datetime, timedelta class Account: diff --git a/abcbank/bank.py b/abcbank/bank.py index c28d2f2..6081f17 100644 --- a/abcbank/bank.py +++ b/abcbank/bank.py @@ -1,4 +1,4 @@ -from .customer import Customer +from abcbank.customer import Customer class Bank: def __init__(self): diff --git a/abcbank/customer.py b/abcbank/customer.py index ef7761f..cddb7d7 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -1,4 +1,4 @@ -from .account import Account +from abcbank.account import Account class Customer: From b6d7294c96ea48fa8eab5013a35b82bf3f241912 Mon Sep 17 00:00:00 2001 From: Connor Hammond Date: Mon, 1 Feb 2016 14:06:45 -0500 Subject: [PATCH 6/6] Final --- abcbank/account.py | 11 +++++++---- abcbank/customer.py | 2 +- bank_tests.py | 9 +++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index 739b93c..bf39ef9 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -52,14 +52,17 @@ def dailyInterestRate(self): def interestEarnedDaily(self): interest = 0 - if self.account_age_in_days > 0: - for day in range(self.account_age_in_days-1): + if self.account_age_in_days == 0: + pass + else: + for day in range(1,self.account_age_in_days): interest += self.dailyInterestRate() return interest def accrueInterest(self): - for day in range(self.account_age_in_days-1): - self.balance += self.accruedDailyInterest() * self.interestEarnedDaily + if self.account_age_in_days>0: + for day in range(self.account_age_in_days-1): + self.balance += self.accruedDailyInterest() * self.interestEarnedDaily() return self.balance diff --git a/abcbank/customer.py b/abcbank/customer.py index cddb7d7..6c7e7f7 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -19,7 +19,7 @@ def numAccs(self): return len(self.accounts) def totalInterestEarned(self): - return sum([a.interestEarned() for a in self.accounts]) + return sum([a.interestEarnedDaily() for a in self.accounts]) def totalAssets(self): return "Total Assets: " + _toDollars(sum([a.balance for a in self.accounts])) diff --git a/bank_tests.py b/bank_tests.py index 9cfa785..5524cfe 100644 --- a/bank_tests.py +++ b/bank_tests.py @@ -16,7 +16,8 @@ def test_checking_account(): bill = bank.addCustomer("Bill") bill_new_checking = bill.openAccount('CHECKING') bill_new_checking.deposit(100.00) - assert_equals(bank.totalInterestPaid(), .1) + bill_new_checking.account_age_in_days = 20 + assert_equals(round(bank.totalInterestPaid(),3), .005) def test_savings_account(): bank = Bank() @@ -44,8 +45,8 @@ def test_transfer(): assert_equals(bill_savings.balance,250.0) if __name__ == '__main__': - # test_customer_summary() - # test_checking_account() + test_customer_summary() + test_checking_account() test_savings_account() - # test_maxi_savings_account() + test_maxi_savings_account() test_transfer() \ No newline at end of file