Part 1
Part 1
Represents a single bank account within the system. Manages all individual Account objects in the system.
Attributes: Attributes:
account_number: A unique identifier for each account. accounts: A dictionary where keys are account_numbers and
balance: A floating-point number representing the current funds. values are corresponding Account objects.
account_holder_name: A string storing the name of the account Objects: Typically, there will be a single Bank instance, for example,
owner. my_bank_system, which orchestrates all account operations.
Deposit
The deposit(account_number, amount) function safely increases the account.balance for the specified account. It ensures funds are
added correctly and reflected immediately.
Withdraw
The withdraw(account_number, amount) function decreases the account.balance after validating that sufficient funds are available,
preventing overdrafts.
Check Balance
The get_balance(account_number) function provides the current account.balance, offering quick access to financial information
without altering the account state.
Transfer
The transfer(from_acc_num, to_acc_num, amount) function atomically combines a withdrawal from one account and a deposit to
another, ensuring a secure and consistent fund movement.
Create Account
The create_account(name, initial_deposit) function instantiates a new Account object and integrates it into the Bank.accounts
system, ready for transactions.
System Interaction Flow: Function Calling
Internal Flow
Action Execution The Bank.deposit() method, for instance,
User Interface User input directly triggers specific function internally calls the
The system features a simple, menu-driven calls. For example, if a user chooses account_object.deposit(amount) method.
command-line interface, providing intuitive 'Deposit', the system will prompt for the This nested calling structure ensures proper
prompts for users to select desired banking account number and the amount, data encapsulation and maintains the
actions. subsequently calling modularity of the system's design.
my_bank_system.deposit(account_num
ber, amount).
Program Structure: Account Class (Python)
class Account:
def __init__(self, account_number, account_holder_name, initial_balance=0.0):
self.account_number = account_number
self.account_holder_name = account_holder_name
self.balance = initial_balance
def get_balance(self):
return self.balance
def __str__(self):
return f"Account No: {self.account_number}, Holder: {self.account_holder_name}, Balance: ${self.balance:.2f}"
This Python code defines the Account class, a core component of our bank management system. It includes an initializer (__init__) to set up account
number, holder name, and initial balance. Methods for deposit and withdraw manage balance changes with validation. The get_balance method
retrieves the current balance, and __str__ provides a readable representation of the account.