navred61's picture
copied from private space
99a41ea
"""Multiple classes example for testing AST parsing."""
class BankAccount:
"""Simple bank account class."""
def __init__(self, account_number, initial_balance=0):
self.account_number = account_number
self.balance = initial_balance
self.transaction_history = []
def deposit(self, amount):
self.balance += amount
self.transaction_history.append(f"Deposit: +{amount}")
def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
self.transaction_history.append(f"Withdrawal: -{amount}")
return True
return False
def get_balance(self):
return self.balance
class Customer:
"""Customer class to hold account information."""
def __init__(self, customer_id, name, email):
self.customer_id = customer_id
self.name = name
self.email = email
self.accounts = []
def add_account(self, account):
self.accounts.append(account)
def get_total_balance(self):
return sum(account.get_balance() for account in self.accounts)
class Bank:
"""Bank class to manage customers and accounts."""
def __init__(self, name):
self.name = name
self.customers = {}
self.next_account_number = 1000
def create_customer(self, name, email):
customer_id = len(self.customers) + 1
customer = Customer(customer_id, name, email)
self.customers[customer_id] = customer
return customer
def create_account(self, customer_id, initial_balance=0):
if customer_id in self.customers:
account = BankAccount(self.next_account_number, initial_balance)
self.customers[customer_id].add_account(account)
self.next_account_number += 1
return account
return None