0% found this document useful (0 votes)
15 views8 pages

Banking System OOP Project Code

The document outlines a Banking System implemented using Object-Oriented Programming in Python. It includes classes for transactions, accounts, and different account types (savings and current), along with methods for account management such as deposit, withdrawal, and balance checking. The system provides a menu-driven interface for users to interact with their accounts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

Banking System OOP Project Code

The document outlines a Banking System implemented using Object-Oriented Programming in Python. It includes classes for transactions, accounts, and different account types (savings and current), along with methods for account management such as deposit, withdrawal, and balance checking. The system provides a menu-driven interface for users to interact with their accounts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

# ============================================================

# Project: Banking System using Object-Oriented Programming

# ============================================================

import datetime

# --------------------- CLASS DEFINITIONS ---------------------

class Transaction:

"""Class to store each transaction detail"""

def __init__(self, date, t_type, amount, balance):

[Link] = date

[Link] = t_type

[Link] = amount

[Link] = balance

def __str__(self):

return f"{[Link]} | {[Link]:<10} | ₹{[Link]:<10} | Balance: ₹{[Link]}"

class Account:

"""Base class representing a bank account"""

daily_withdraw_limit = 20000 # daily withdrawal limit

def __init__(self, acc_no, name, acc_type):


self.__acc_no = acc_no

self.__name = name

self.__acc_type = acc_type

self.__balance = 0

self.__transactions = []

# Encapsulation: getter methods

def get_account_number(self):

return self.__acc_no

def get_name(self):

return self.__name

def get_balance(self):

return self.__balance

# Deposit money

def deposit(self, amount):

if amount <= 0:

print("⚠️Deposit amount must be positive!")

return

self.__balance += amount

self.__record_transaction("Deposit", amount)

print(f"✅ ₹{amount} deposited successfully!")


# Withdraw money

def withdraw(self, amount):

today = [Link]().strftime("%Y-%m-%d")

# Calculate today's withdrawals

today_withdrawals = sum(

[Link] for t in self.__transactions if [Link] == "Withdraw" and [Link](today)

if amount <= 0:

print("⚠️Withdrawal amount must be positive!")

elif amount > self.__balance:

print("❌ Insufficient balance!")

elif today_withdrawals + amount > Account.daily_withdraw_limit:

print("⚠️Exceeded daily withdrawal limit!")

else:

self.__balance -= amount

self.__record_transaction("Withdraw", amount)

print(f"✅ ₹{amount} withdrawn successfully!")

# Record transaction in history

def __record_transaction(self, t_type, amount):

date = [Link]().strftime("%Y-%m-%d %H:%M:%S")

self.__transactions.append(Transaction(date, t_type, amount, self.__balance))


# Check balance

def check_balance(self):

print(f"💰 Current Balance: ₹{self.__balance}")

# Display account info

def display_info(self):

print("\n----- ACCOUNT INFORMATION -----")

print(f"Account No : {self.__acc_no}")

print(f"Name : {self.__name}")

print(f"Account Type: {self.__acc_type}")

print(f"Balance : ₹{self.__balance}")

print("-------------------------------")

# Print passbook

def print_passbook(self, from_date=None, to_date=None):

print("\n----- PASSBOOK -----")

if not self.__transactions:

print("No transactions yet.")

return

for t in self.__transactions:

if from_date and to_date:

t_date = [Link]([Link]()[0], "%Y-%m-%d").date()

if not (from_date <= t_date <= to_date):

continue

print(t)
print("--------------------")

# Derived Classes (Inheritance)

class SavingsAccount(Account):

def __init__(self, acc_no, name):

super().__init__(acc_no, name, "Savings")

class CurrentAccount(Account):

def __init__(self, acc_no, name):

super().__init__(acc_no, name, "Current")

# --------------------- BANK SYSTEM ---------------------

class BankSystem:

def __init__(self):

[Link] = {}

def create_account(self):

acc_no = input("Enter Account Number: ")

name = input("Enter Account Holder Name: ")

acc_type = input("Enter Account Type (Savings/Current): ").capitalize()


if acc_type == "Savings":

[Link][acc_no] = SavingsAccount(acc_no, name)

elif acc_type == "Current":

[Link][acc_no] = CurrentAccount(acc_no, name)

else:

print("⚠️Invalid account type!")

return

print("✅ Account created successfully!")

def get_account(self, acc_no):

return [Link](acc_no, None)

def menu(self):

while True:

print("""

=========== BANKING SYSTEM ===========

1. Create Account

2. Deposit Money

3. Withdraw Money

4. Check Balance

5. Display Account Info

6. Print Passbook

7. Exit

=====================================
""")

choice = input("Enter your choice: ")

if choice == "1":

self.create_account()

elif choice in ["2", "3", "4", "5", "6"]:

acc_no = input("Enter Account Number: ")

acc = self.get_account(acc_no)

if not acc:

print("⚠️Account not found!")

continue

if choice == "2":

amt = float(input("Enter amount to deposit: "))

[Link](amt)

elif choice == "3":

amt = float(input("Enter amount to withdraw: "))

[Link](amt)

elif choice == "4":

acc.check_balance()

elif choice == "5":

acc.display_info()

elif choice == "6":

from_d = input("From Date (YYYY-MM-DD) or leave blank: ")


to_d = input("To Date (YYYY-MM-DD) or leave blank: ")

if from_d and to_d:

from_date = [Link](from_d, "%Y-%m-%d").date()

to_date = [Link](to_d, "%Y-%m-%d").date()

acc.print_passbook(from_date, to_date)

else:

acc.print_passbook()

elif choice == "7":

print("🙏 Thank you for banking with us!")

break

else:

print("⚠️Invalid choice, try again.")

# --------------------- MAIN DRIVER CODE ---------------------

if __name__ == "__main__":

bank = BankSystem()

[Link]()

You might also like