File size: 1,897 Bytes
99a41ea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
"""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
|