Object Oriented Programming: Objects inside of Objects (Pt. 3)

In today’s lecture, our objective will be to implement a simple Bank class that will store a list of customers. 

import copy

class Customer:
"""
Customer class contains 5 attributes: first name, last name, identification number,
account balance, and PIN number (which is stored as a string). It contains methods
for printing the class, depositing money, withdrawing money, setting the PIN, and
verifying the PIN,
"""

def __init__(self, firstname, lastname, id):
"""
This function initializes the Customer class. It requires a first name,
last name, and ID number. The account balance is set to zero and the pin
is set to 1234.
"""

self.firstname = firstname
self.lastname = lastname
self.id = id
self.balance = 0.0
self.pin = '1234'

def __str__(self):
"""
Constructs the string to print the Customer class. Prints the first name,
last name, and the account balance.
"""
return self.firstname + " " + self.lastname + ": " + str(self.balance)

def __repr__(self):
"""
Constructs the string to print the Customer class. Prints the first name,
last name, and the account balance.
"""
return self.firstname[0] + " " + self.lastname + ": " + str(self.balance)

def deposit(self,value):
"""
Adds the input argument, value, to the account balance.
"""
self.balance += value

def withdraw(self,value,pin):

if self.validPin(pin):
if self.balance >= value:
self.balance -= value
return value
else:
print('insufficient funds')
return 0

def setPin(self, oldpin, newpin):
if len(newpin) == 4:
if self.pin == oldpin:
self.pin = newpin
print('Pin successfully updated.')
else:
print('Pin not updated.')



def validPin(self,pin):
return self.pin == pin

class Bank:
"""
"""

def __init__(self, name):
"""
"""
self.name = name
self.customers = dict()
self.cash = 0.0
self.debt = 0.0

def addCustomer(self, customer):
"""
"""

self.customers[customer.id] = customer

def deposit(self, id, amt):
#self.customers[id].deposit(amt)

c = copy.copy(self.customers[id])
c.deposit(amt)
self.customers[id] = copy.copy(c)

def calcCash(self):
total = 0.0

for cust in self.customers.values():
total += cust.balance

self.cash = total
css.php