Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions abcbank/account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from abcbank.transaction import Transaction
from abcbank.customer import Customer
from date_provider import DateProvider

CHECKING = 0
SAVINGS = 1
Expand All @@ -9,6 +11,7 @@ class Account:
def __init__(self, accountType):
self.accountType = accountType
self.transactions = []
self.logintimes= []

def deposit(self, amount):
if (amount <= 0):
Expand All @@ -22,22 +25,42 @@ 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:
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])
return sum([t.amount for t in self.transactions])
4 changes: 2 additions & 2 deletions tests/customer_tests.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)
assert_equals(oscar.numAccs(), 3)