UML

mail@pastecode.io avatar
unknown
python
3 years ago
4.5 kB
2
Indexable
Never
import datetime

class Bank:
    
    branch_list=[]

    def __init__(self, name, code):
        self.name=name
        self.code=code

    def addBranch(self, BranchObject):
        self.branch_list.append(BranchObject)

    def removeBranch(self, branch_code):
        for b in Bank.branch_list:
            if b.branch_code == branch_code:
            	Bank.branch_list.remove(b)

    def updateInfo(self, newname, newcode):
        self.newname=newname
        self.newcode=newcode

    def getBranch(self, branch_code):
        for b in Bank.branch_list:
            if b.branch_code == branch_code:
            	return Bank.branch_list.remove(b)
        return None

    def getAllBranch(self):
        for i in Bank.branch_list:
            print(Bank.branch_list[i][0], Bank.branch_list[i][1])


class Branch:

    account_list=[]


    def __init__(self, branch_code, city, bank):
        self.branch_code=branch_code
        self.city=city
        self.bank=bank

    def addAccount(self, accountObj):
        self.account_list.append(accountObj)

    def removeAccount(self, account_number):
        for acc in Branch.account_list:
            if acc.acc_no == account_number:
            	Branch.account_list.remove(acc)

    def getAccount(self, account_number):
        for acc in Branch.account_list:
            if acc.acc_no == account_number:
            	return Branch.account_list.remove(acc)
        return None

    def updateInfo(self, branch_code, city):
        self.branch_code=branch_code
        self.city=city

class Account:

    balance=0

    def __init__(self, acc_no, BranchObj):
        self.acc_no=acc_no
        self.BranchObj=BranchObj

        Account.balance=0

    def  debitAmmount(self, amt):
        Account.balance-=amt


    def creditAmmount(self, amt):
        Account.balance+=amt

    def getBalance(self):
        return Account.balance



class Savings_account(Account):

    open_date = datetime.datetime.now()
    min_balance=0


    def __init__(self, acc_no, branch, min_balance):
        self.acc_no=acc_no
        self.branch=branch
        self.min_balance=min_balance

    def removeCustomer(self):
        self.customer = None

    def setCustomer(self, customer_obj):
        self.customer = customer_obj

    def  debitAmmount(self, amt):
        Account.balance-=amt
        if Account.balance<Savings_account.min_balance:
            Account.balance=Savings_account.min_balance    


class Current_Account(Account):

    open_date = datetime.datetime.now()
    

    def __init__(self, acc_no, branch, interest_rate):
        self.acc_no=acc_no
        self.branch=branch
        self.interest_rate= interest_rate


    def setCustomer(self, customer_obj):
        self.customer = customer_obj

    def removeCustomer(self):
        self.customer = None

    def  debitAmmount(self, amt):
        Account.balance-=amt
        if Account.balance<0:
            Account.balance=0    

class Customer:

    Next_id= 1

    def __init__(self,name,address,phone):
        self.name=name
        self.address=address
        self.phone=phone
        Customer.Next_id+=1

    def setSavingsAcc(self, savings_acc):
        self.savings_acc = savings_acc

    def getSavingsAcc(self):
        return self.savings_acc

    def setCurrentAcc(self, current_acc):
        self.current_acc = current_acc

    def getCurrentAcc(self):
        return self.current_acc




b1 = Bank("DBBL", 1256)
b2= Bank("EBL", 1257)

b1.branch_list=[]
b2.branch_list=[]

br1=Branch(1, 'Dhanmondi', b1)
br2=Branch(2,'Motijheel', b1)
br3=Branch(3, 'Mirpur', b2)
br4=Branch(4,'Gulshan', b2)

br1.account_list=[]
br2.account_list=[]
br3.account_list=[]
br4.account_list=[]


b1.branch_list=[br1, br2]
b2.branch_list=[br3,br4]

print(b1.getAllBranch())
print(b2.getAllBranch())

s1=Savings_account(1234,br1, 500)
s2=Savings_account(1235, br4, 1000)

c1= Current_Account(5432, br1, 0.10)
c2= Current_Account(5431, br3, 0.12)

br1.account_list=[s1,c1]
br3.account_list=[c2]
br4.account_list=[s2]

cs1=Customer("afif", "Dhaka", "01911111111")
cs2=Customer("Sohan", "Dhaka", "0151111111")

cs1.setSavingsAcc(s1)
cs2.setSavingsAcc(s2)
cs1.setCurrentAcc(c1)
cs2.setCurrentAcc(c2)

s1.setCustomer(cs1)
c1.setCustomer(cs1)
s2.setCustomer(cs2)
c2.setCustomer(cs2)