Skip to content

Cedar-Creatives/python-wk-5-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏦 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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages