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
4 changes: 4 additions & 0 deletions abcbank/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from account import Account
from bank import Bank
from customer import Customer
from transaction import Transaction
59 changes: 28 additions & 31 deletions abcbank/account.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
from abcbank.transaction import Transaction

CHECKING = 0
SAVINGS = 1
MAXI_SAVINGS = 2

from datetime import datetime
from transaction import Transaction

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))

def withdraw(self, amount):
if (amount <= 0):
raise ValueError("amount must be greater than zero")
def performTransaction(self, transaction):
self.transactions.append(transaction)
if transaction.type == "Deposit":
self.balance += transaction.amount
else:
self.transactions.append(Transaction(-amount))
self.balance -= transaction.amount
return self

def interestEarned(self):
amount = self.sumTransactions()
if self.accountType == SAVINGS:
if (amount <= 1000):
return amount * 0.001
print(self.balance)
if self.accountType == "SAVINGS":
if (self.balance <= 1000):
return self.balance * 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
return 1 + (self.balance - 1000) * 0.002
if self.accountType == "MAXI_SAVINGS":
noWithdrawalsInPast10Days = True
for t in self.transactions:
if t.type == "WITHDRAWAL" and (datetime.now - t.transactionDate).days < 10:
noWithdrawalsInPast10Days = False
if noWithdrawalsInPast10Days == True:
return self.balance * 0.05
else:
return 70 + (amount - 2000) * 0.1
else:
return amount * 0.001
return self.balance * 0.001
if self.accountType == "CHECKING":
return self.balance * 0.001




def sumTransactions(self, checkAllTransactions=True):
return sum([t.amount for t in self.transactions])

8 changes: 2 additions & 6 deletions abcbank/bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ def totalInterestPaid(self):
total += c.totalInterestEarned()
return total
def getFirstCustomer(self):
try:
self.customers = None
return self.customers[0].name
except Exception as e:
print(e)
return "Error"
return self.customers[0].name

28 changes: 9 additions & 19 deletions abcbank/customer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from account import CHECKING, SAVINGS, MAXI_SAVINGS


class Customer:
def __init__(self, name):
self.name = name
Expand All @@ -21,35 +18,28 @@ def getStatement(self):
# JIRA-123 Change by Joe Bloggs 29/7/1988 start
statement = None # reset statement to null here
# JIRA-123 Change by Joe Bloggs 29/7/1988 end
totalAcrossAllAccounts = sum([a.sumTransactions() for a in self.accounts])
totalAcrossAllAccounts = sum([a.balance for a in self.accounts])
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)
return statement

def statementForAccount(self, account):
accountType = "\n\n\n"
if account.accountType == CHECKING:
accountType = "account.type"
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:
accountType = "\n\nMaxi Savings Account\n"
transactionSummary = [self.withdrawalOrDepositText(t) + " " + _toDollars(abs(t.amount))
if account.accountType == "MAXI_SAVINGS":
accountType = "\n\nMaxi Savings Accounts\n"

transactionSummary = [t.type + " " + _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]))
totalSummary = "Total " + _toDollars(account.balance)
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):
return "${:1.2f}".format(number)
17 changes: 15 additions & 2 deletions abcbank/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@


class Transaction:
def __init__(self, amount):
def __init__(self, withdrawalOrDeposit, amount):
self.amount = amount
self.transactionDate = datetime.now()
self.type = withdrawalOrDeposit
self.transactionDate = datetime.now()

def deposit(self, amount):
if (amount <= 0):
raise ValueError("You can only deposit an amount greater than 0.")
else:
self.transactions.append(Transaction(amount, "Deposit"))

def withdraw(self, amount):
if (amount <= 0):
raise ValueError("You can only withdraw an amount greater than 0.")
else:
self.transactions.append(Transaction(amount, "Withdrawal"))
52 changes: 52 additions & 0 deletions tests/account_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from nose.tools import assert_equals, nottest

from abcbank.account import Account
from abcbank.customer import Customer
from abcbank.transaction import Transaction
from abcbank.bank import Bank

def test_checking_account():
bank = Bank()
checkingAccount = Account("CHECKING")
bill = Customer("Bill").openAccount(checkingAccount)
bank.addCustomer(bill)
checkingAccount.performTransaction(Transaction("Deposit", 100))
assert_equals(checkingAccount.accountType, "CHECKING")


def test_savings_account():
bank = Bank()
savingsAccount = Account("SAVINGS")
bank.addCustomer(Customer("Bill").openAccount(savingsAccount))
savingsAccount.performTransaction(Transaction("Deposit", 1500))
assert_equals(savingsAccount.accountType, "SAVINGS")


def test_maxi_savings_account():
bank = Bank()
maxiSavingsAccount = Account("MAXI_SAVINGS")
bank.addCustomer(Customer("Bill").openAccount(maxiSavingsAccount))
maxiSavingsAccount.performTransaction(Transaction("Deposit", 3000))
assert_equals(maxiSavingsAccount.accountType, "MAXI_SAVINGS")

def test_checking_account_interest():
bank = Bank()
checkingAccount = Account("CHECKING")
bill = Customer("Bill").openAccount(checkingAccount)
bank.addCustomer(bill)
checkingAccount.performTransaction(Transaction("Deposit", 100))
assert_equals(checkingAccount.interestEarned(), .1)

def test_savings_account_interest():
bank = Bank()
savingsAccount = Account("SAVINGS")
bank.addCustomer(Customer("Bill").openAccount(savingsAccount))
savingsAccount.performTransaction(Transaction("Deposit", 1500))
assert_equals(savingsAccount.interestEarned(), 2)

def test_maxi_savings_account_interest():
bank = Bank()
maxiSavingsAccount = Account("MAXI_SAVINGS")
bank.addCustomer(Customer("Bill").openAccount(maxiSavingsAccount))
maxiSavingsAccount.performTransaction(Transaction("Deposit", 3000))
assert_equals(maxiSavingsAccount.interestEarned(), 150)
48 changes: 22 additions & 26 deletions tests/bank_tests.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
from nose.tools import assert_equals

from account import Account, CHECKING, MAXI_SAVINGS, SAVINGS
from bank import Bank
from customer import Customer
from abcbank.account import Account
from abcbank.bank import Bank
from abcbank.customer import Customer
from abcbank.transaction import Transaction

def test_add_customer():
bank = Bank()
john = Customer("John")
bank.addCustomer(john)
assert_equals(bank.getFirstCustomer(), "John")

def test_customer_summary():
bank = Bank()
john = Customer("John").openAccount(Account(CHECKING))
john = Customer("John").openAccount(Account("CHECKING"))
bank.addCustomer(john)
assert_equals(bank.customerSummary(),
"Customer Summary\n - John (1 account)")

def test_total_interest_paid():
bank = Bank()
checkingAccount = Account("CHECKING")
bill = Customer("Bill").openAccount(checkingAccount)
bank.addCustomer(bill)
checkingAccount.performTransaction(Transaction("Deposit", 1000))
checking2Account = Account("CHECKING")
john = Customer("John").openAccount(checking2Account)
bank.addCustomer(john)
checkingAccount.performTransaction(Transaction("Deposit", 1000))
assert_equals(bank.totalInterestPaid(), 2)

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)
45 changes: 22 additions & 23 deletions tests/customer_tests.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
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)
from abcbank.account import Account
from abcbank.customer import Customer
from abcbank.transaction import Transaction


def test_getStatement():
checkingAccount = Account("CHECKING")
savingsAccount = Account("SAVINGS")
henry = Customer("Henry")
henry.openAccount(checkingAccount)
henry.openAccount(savingsAccount)
checkingAccount.performTransaction(Transaction("Deposit",100.0))
savingsAccount.performTransaction(Transaction("Deposit",4000.0))
savingsAccount.performTransaction(Transaction("Withdrawal",200.0))
print("Savings Account Balance: " + str(savingsAccount.balance))
print(henry.getStatement())
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\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))
oscar = Customer("Oscar").openAccount(Account("SAVINGS"))
assert_equals(oscar.numAccs(), 1)


def test_twoAccounts():
oscar = Customer("Oscar").openAccount(Account(SAVINGS))
oscar.openAccount(Account(CHECKING))
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)
28 changes: 23 additions & 5 deletions tests/transaction_tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
from nose.tools import assert_is_instance
from nose.tools import assert_equals

from transaction import Transaction
from abcbank.account import Account
from abcbank.customer import Customer
from abcbank.transaction import Transaction
from abcbank.bank import Bank
from abcbank.transaction import Transaction

def test_deposit():
bank = Bank()
checkingAccount = Account("CHECKING")
bill = Customer("Bill").openAccount(checkingAccount)
bank.addCustomer(bill)
checkingAccount.performTransaction(Transaction("Deposit", 100))
assert_equals(checkingAccount.balance, 100)

def test_type():
t = Transaction(5)
assert_is_instance(t, Transaction, "correct type")
def test_withdrawal():
bank = Bank()
checkingAccount = Account("CHECKING")
bill = Customer("Bill").openAccount(checkingAccount)
bank.addCustomer(bill)
checkingAccount.performTransaction(Transaction("Deposit", 1000))
checkingAccount.performTransaction(Transaction("Withdrawal", 900))
assert_equals(checkingAccount.balance, 100)