BankAccount class
In the main code:
In the class, add methods to:
class BankAccount:
# Initializing
def __init__(self,name,balance):
self.name=name
self.balance=balance
def getName(self):
return self.name
def getBalance(self):
return self.balance
class BankAccountList:
# Initializing
def __init__(self):
self.listBankAccounts =[]
def addBankAccountToList(self,bankAccount):
self.listBankAccounts.append(bankAccount)
#calculate and return the totalDeposits() for all accounts
def calculateTotalDeposits(self):
sumResult=0
for account in self.listBankAccounts:
sumResult+=account.getBalance()
return sumResult
#find and return the name of the large account
def getnameLargeAccount(self):
largeAccount=self.listBankAccounts[0]
for account in self.listBankAccounts:
if account.getBalance()>largeAccount.getBalance():
largeAccount=account
return largeAccount
def displayAllBankAccounts(self):
for account in self.listBankAccounts:
print(f"The BankAccount name: {account.getName()}")
print(f"The BankAccount balance: {account.getBalance()}")
print(f"The total deposits for all accounts: {self.calculateTotalDeposits()}")
print(f"The name of the large account: {self.getnameLargeAccount().getName()} balance: {self.getnameLargeAccount().getBalance()}")
n =int(input("Enter number of bank accounts: "))
ba=BankAccountList()
for i in range(0,n):
name=input("Enter name: ")
balance=float(input("Enter balance: "))
b=BankAccount(name,balance)
ba.addBankAccountToList(b)
ba.displayAllBankAccounts()
Comments
Leave a comment