Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

class Account:

# Define an init(constructor) method with attributes shared by all accounts


def __init__(self,acc_num,opening_deposit):
self.acc_num = acc_num
self.balance = opening_deposit

# Define a __str__ method to return a recognizable string


def __str__(self):
return f'${self.balance:.2f}'
# Define a universal method to accept deposits
def deposit(self,dep_amt):
self.balance += dep_amt
# Define a universal method to facilitate withdrawals
def withdraw(self,wth_amt):
if self.balance >= wth_amt:
self.balance -= wth_amt
else:
print('Insufficient Funds Available')
class Current(Account):
def __init__(self,acc_num,opening_deposit):
# Accessing the base class
super().__init__(acc_num,opening_deposit)

# Define a __str__ method that returns a string specific to checking accounts


def __str__(self):
return f'Current Account #{self.acc_num}\nBalance: {Account.__str__(self)}'
class Savings(Account):
def __init__(self,acc_num,opening_deposit):
# Run the base class __init__
super().__init__(acc_num,opening_deposit)

# Define a __str__ method that returns a string specific to Savings Accounts


def __str__(self):
return 'Savings Account:#{} \nBalance:
{}'.format(self.acc_num,Account.__str__(self))
class Business(Account):
def __init__(self,acc_num,opening_deposit):
super().__init__(acc_num,opening_deposit)

# Define a __str__ method that returns a string specific to Business Accounts


def __str__(self):
return f'Business Account:#{self.acc_num}\nBalance:
{Account.__str__(self)}'
class Customer:
def __init__(self,name,PIN):
self.name = name
self.PIN = PIN
#Dictionary of accounts with lists to hold multiple accounts
self.accts = {'C':[], 'S':[], 'B':[]}

def __str__(self):
return self.name

def open_current(self,acc_num,opening_deposit):
self.accts['C'].append(Current(acc_num,opening_deposit))

def open_savings(self,acc_num,opening_deposit):
self.accts['S'].append(Savings(acc_num,opening_deposit))
def open_business(self,acc_num,opening_deposit):
self.accts['B'].append(Business(acc_num,opening_deposit))

# Method that computes total deposits


def get_total_deposit(self):
total = 0
for acct in self.accts['C']:
print(acct)
total += acct.balance
for acct in self.accts['S']:
print(acct)
total += acct.balance
for acct in self.accts['V']:
print(acct)
total += acct.balance
print(f'Comdined Deposits: ${total:.2f}')
def make_dep(cust,acct_type,acct_num,dep_amt):
"""
make_dep(cust, acct_type, acct_num, dep_amt)
cust = variable name (Customer record/ID)
acct_type = string 'C' 'S' or 'B'
acct_num = integer
dep_amt = integer
"""
for acct in cust.accts[acct_type]:
if acct.acc_num == acct_num:
acct.deposit(dep_amt)

def make_wd(cust,acct_type,acct_num,wd_amt):
"""
make_dep(cust, acct_type, acct_num, wd_amt)
cust = variable name (Customer record/ID)
acct_type = string 'C' 'S' or 'B'
acct_num = integer
wd_amt = integer
"""
for acct in cust.accts[acct_type]:
if acct.acc_num == acct_num:
acct.withdraw(wth_amt)

You might also like