#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Nov 8 13:18:20 2022 @author: Mohammad Hammoud """ class Customer: def __init__(self, name, cid): self.cname = name self.cid = cid def getCName(self): return self.cname def getCId(self): return self.cid c1 = Customer("Mohammad", 667123) print(c1.getCName()) print(c1.getCId()) c2 = Customer("Khaled", 493057) print(c2.getCName()) print(c2.getCId()) class Account: #This is a static or class variable counter = 0 def __init__(self, customer, balance): self.customer = customer self.balance = balance #You can access the static variable through the name of the class Account.counter += 1 self.number = Account.counter def getAccountNumber(self): return self.number def getAccountBalance(self): return self.balance def getAccountOwner(self): return self.customer def deposit(self, amount): self.balance = self.balance + amount def withdraw(self, amount): if amount <= self.balance: self.balance = self.balance - amount else: print("You do not have sufficient funds!") a1 = Account(c1, 100) a2 = Account(c2, 200) print(a1.getAccountNumber()) print(a2.getAccountNumber()) print("The number of accounts created thus far is", Account.counter) print(a1.getAccountBalance()) a1.deposit(230) print(a1.getAccountBalance()) a1.withdraw(30) print(a1.getAccountBalance()) a1.withdraw(500) class Bank: #All accounts will be stored in one dictionary named accounts. def __init__(self, bank_name, accounts): self.bname = bank_name self.accounts = accounts # ============================================================================= # The key of each element in the accounts dictionary is the account number # and the value is the account itself. # ============================================================================= def addAccount(self, account): if self.accounts.get(account.getAccountNumber(), -1) == -1: self.accounts[account.getAccountNumber()] = account else: print("Account already exists") def getAccount(self, account): if account.getAccountNumber() in self.accounts: return self.accounts[account.getAccountNumber()] else: print("Account does not exist") accounts = {a1.getAccountNumber():a1, a2.getAccountNumber():a2} b = Bank("QNB", accounts) print(b.getAccount(a1).getAccountOwner().getCName())