π¦ Bank Account & π³ Payment Methods β OOP Assignment π Overview
This project demonstrates Object-Oriented Programming (OOP) concepts in Python using two different scenarios:
Assignment 1 β Bank Account
A simple BankAccount class that supports deposits, withdrawals, and checking balances.
Demonstrates encapsulation, constructors, and methods.
Activity 2 β Payment Methods (Polymorphism Challenge)
A PaymentMethod base class with subclasses like CreditCard, PayPal, and Bitcoin.
Demonstrates polymorphism, where the same method (pay()) behaves differently depending on the payment method.
π Assignment 1: Bank Account
File: bank_account.py
Features:
Initialize accounts with owner, account number, and balance.
Deposit money into the account.
Withdraw money (with balance checks).
View current balance.
Example: acc1 = BankAccount("001", "Alice", 500) acc1.deposit(200) # π° 200 deposited. New balance: 700 acc1.withdraw(100) # π§ 100 withdrawn. New balance: 600 acc1.check_balance() # π Balance for Alice: 600
π Activity 2: Payment Methods (Polymorphism Challenge)
File: payment_methods.py
Features:
Abstract PaymentMethod base class.
Subclasses: CreditCard, PayPal, and Bitcoin.
Each subclass implements its own version of the pay() method.
Example: methods = [CreditCard(), PayPal(), Bitcoin()]
for method in methods: method.pay(100)
π³ Output:
π³ Paid 100 using Credit Card. π Paid 100 via PayPal. βΏ Paid 100 with Bitcoin.
π How to Run
Clone or download the project folder.
Run the Python files:
python bank_account.py python payment_methods.py
π― Outcomes
Learned how to create custom classes with attributes and methods.
Practiced encapsulation and constructors in Python.
Explored polymorphism by implementing the same method differently across classes.
Gained confidence in designing simple, real-world OOP systems.