Skip to content

Ezz08/Bank-System-OOP-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple Bank System - OOP Project

Overview

This project is a simple banking system implemented in Python to demonstrate core Object-Oriented Programming (OOP) concepts.
It includes basic bank account functionality, savings accounts with interest, and calculations using data structures.


Classes

1. Account

Represents a standard bank account.

Attributes:

  • owner_name: Name of the account owner.
  • account_number: Unique account number.
  • balance: Current balance.
  • total_accounts (Class Variable): Tracks total number of accounts.

Methods:

  • deposit(amount): Add money to the account.
  • withdraw(amount): Withdraw money from the account.
  • show_balance (Property): Returns the current balance.
  • __str__(): Returns a readable string representation.
  • __add__(other): Returns the sum of two account balances.
  • __lt__(other): Compares two accounts by balance.
  • __getitem__(key): Access account info by key (owner_name, account_number, balance).
  • get_count() (Class Method): Returns the total number of accounts.

2. SavingsAccount (Inherits from Account)

Represents a savings account with interest.

Additional Attributes:

  • interest_rate: Interest rate in percentage.

Additional Methods:

  • add_interest(): Calculates interest and adds it to the balance.
  • withdraw(amount): Overrides the parent withdraw method (Polymorphism) to show a different message.

3. Average

Calculates the average balance of multiple accounts using a list (array).

Attributes:

  • accounts: List to store all account objects.

Methods:

  • add_account(account): Adds an account to the list.
  • average_balance(): Calculates and prints the average balance of all accounts.

Main Features

  1. Basic Banking Operations: Deposit, Withdraw, Show Balance.
  2. Savings Account Functionality: Add interest automatically.
  3. Magic Methods: __str__, __add__, __lt__, __getitem__.
  4. Class Variables & Class Methods: Track total accounts.
  5. Property Decorators: Access balance safely.
  6. Data Structure Integration: Calculate average balances of multiple accounts.
  7. Polymorphism: withdraw method behaves differently in SavingsAccount.

Example Usage (main.py)

from account import Account, SavingsAccount, Average

# Create accounts
acc1 = Account("Ezz", "100", 54000)
acc2 = Account("Ali", "112", 35000)
sav1 = SavingsAccount("Mostafa", "287", 12000, 8)
sav2 = SavingsAccount("Adham", "265", 23000, 5)

# Transactions
acc1.deposit(10000)
acc2.withdraw(300)
sav1.deposit(450)
sav2.withdraw(1000)
sav1.add_interest()
sav2.add_interest()

# Magic Methods
print(acc1)                 # __str__
print(acc1 + acc2)          # __add__
print(acc1 < acc2)          # __lt__
print(acc1["owner_name"])   # __getitem__

# Show balances
print(acc1.show_balance)
print(sav1.show_balance)

# Average balance calculation
avg_calc = Average()
avg_calc.add_account(acc1)
avg_calc.add_account(acc2)
avg_calc.add_account(sav1)
avg_calc.add_account(sav2)
avg_calc.average_balance()

# Total accounts
print(Account.get_count())

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages