Untitled

mail@pastecode.io avatar
unknown
python
21 days ago
2.1 kB
2
Indexable
Never
class Bank:
    def __init__(self):
        self.accounts = []

    def create_savings_account(self, account_number, account_holder, initial_balance=0, interest_rate=1.5):
        account = SavingsAccount(account_number, account_holder, initial_balance, interest_rate)
        self.accounts.append(account)
        print(f"Savings account {account_number} for {account_holder} created with balance ${initial_balance} and interest rate {interest_rate}%.")

    def create_checking_account(self, account_number, account_holder, initial_balance=0, overdraft_limit=500):
        account = CheckingAccount(account_number, account_holder, initial_balance, overdraft_limit)
        self.accounts.append(account)
        print(f"Checking account {account_number} for {account_holder} created with balance ${initial_balance} and overdraft limit ${overdraft_limit}.")

    def find_account(self, account_number):
        for account in self.accounts:
            if account.account_number == account_number:
                return account
        print("Account not found.")
        return None

    def delete_account(self, account_number):
        account = self.find_account(account_number)
        if account:
            self.accounts.remove(account)
            print(f"Account {account_number} deleted.")

    def list_accounts(self):
        if self.accounts:
            print("Bank Accounts:")
            for account in self.accounts:
                print(f" - {account.account_holder} ({account.account_number}): ${account.balance}")
        else:
            print("No accounts in the bank.")

# Example Usage
bank = Bank()
bank.create_savings_account("789012", "Alice Johnson", 1000, interest_rate=2)
bank.create_checking_account("345678", "Bob Brown", 500, overdraft_limit=1000)

bank.list_accounts()

alice_account = bank.find_account("789012")
bob_account = bank.find_account("345678")

alice_account.apply_interest()
bob_account.withdraw(700)

bank.list_accounts()

alice_account.show_transaction_history()
bob_account.show_transaction_history()
Leave a Comment