From d58522219103cbb99069f8065703e4bb8aa427b4 Mon Sep 17 00:00:00 2001 From: malhilli Date: Wed, 11 Nov 2015 18:08:56 -0500 Subject: [PATCH 1/3] Update account.py --- abcbank/account.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/abcbank/account.py b/abcbank/account.py index e010009..c4480c4 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,4 +1,6 @@ from abcbank.transaction import Transaction +from abcbank.customer import Customer + CHECKING = 0 SAVINGS = 1 @@ -22,6 +24,17 @@ def withdraw(self, amount): else: self.transactions.append(Transaction(-amount)) + def transfer(self,initial_account,final_account,amount): + if (amount <= 0): + raise ValueError("amount must be greater than zero") + elif Customer.numAccs()<=1: + raise ValueError("You must have at least 2 accounts") + else: + self.accountType=initial_account + self.withdraw(amount) + self.accountType=final_account + self.deposit(amount) + def interestEarned(self): amount = self.sumTransactions() if self.accountType == SAVINGS: @@ -40,4 +53,4 @@ def interestEarned(self): return amount * 0.001 def sumTransactions(self, checkAllTransactions=True): - return sum([t.amount for t in self.transactions]) \ No newline at end of file + return sum([t.amount for t in self.transactions]) From c08910a9dbef070b4f6f41b1dc73df89126483b9 Mon Sep 17 00:00:00 2001 From: malhilli Date: Wed, 11 Nov 2015 18:11:42 -0500 Subject: [PATCH 2/3] Update customer_tests.py --- tests/customer_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/customer_tests.py b/tests/customer_tests.py index 0211a4f..264cda8 100644 --- a/tests/customer_tests.py +++ b/tests/customer_tests.py @@ -1,6 +1,6 @@ from nose.tools import assert_equals, nottest -from account import Account, CHECKING, SAVINGS +from account import Account, CHECKING, SAVINGS, MAXI_SAVINGS from customer import Customer @@ -33,4 +33,4 @@ def test_twoAccounts(): def test_threeAccounts(): oscar = Customer("Oscar").openAccount(Account(SAVINGS)) oscar.openAccount(Account(CHECKING)) - assert_equals(oscar.numAccs(), 3) \ No newline at end of file + assert_equals(oscar.numAccs(), 3) From 09cf96e8856009dbbc0cf837a5ffd21a1f91cfae Mon Sep 17 00:00:00 2001 From: malhilli Date: Wed, 11 Nov 2015 18:46:47 -0500 Subject: [PATCH 3/3] Update account.py --- abcbank/account.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index c4480c4..1841aab 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,6 +1,6 @@ from abcbank.transaction import Transaction from abcbank.customer import Customer - +from date_provider import DateProvider CHECKING = 0 SAVINGS = 1 @@ -11,6 +11,7 @@ class Account: def __init__(self, accountType): self.accountType = accountType self.transactions = [] + self.logintimes= [] def deposit(self, amount): if (amount <= 0): @@ -37,20 +38,29 @@ def transfer(self,initial_account,final_account,amount): def interestEarned(self): amount = self.sumTransactions() - if self.accountType == SAVINGS: - if (amount <= 1000): - return amount * 0.001 - 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 - else: - return 70 + (amount - 2000) * 0.1 + #This is a false date for testing. A real account would already have recorded the previous transactions + t=date('2015','11','09') + self.logintimes.append(t) + + currentTime=DateProvider() + if self.logintimes is empty: + return amount*0 else: - return amount * 0.001 + instance=len(self.logintimes) + lasLogin=self.logintimes[instance] + diff=currentTime-lasLogin + if self.accountType == SAVINGS: + if (amount <= 1000): + return amount * 0.001*diff.days + else: + return 1 + (amount - 1000) * 0.002*diff.days + if self.accountType == MAXI_SAVINGS: + if diff.day >=10: + return amount * 0.05*diff.days + else: + return amount * 0.001*diff.days + else: + return amount * 0.001*diff.days def sumTransactions(self, checkAllTransactions=True): return sum([t.amount for t in self.transactions])