This project completes the PLP Python Week 5 OOP assignment, demonstrating fundamental Object-Oriented Programming concepts through two main activities.
- ✅ Create a class representing anything you like - Smartphone class chosen
- ✅ Add attributes and methods to bring the class to life
- ✅ Use constructors to initialize each object with unique values
- ✅ Add an inheritance layer to explore polymorphism or encapsulation
-
Base Class:
Smartphone- Attributes: brand, model, storage, battery_life, is_on, apps_installed
- Methods: power_on(), power_off(), install_app(), get_info()
- Constructor: Initializes each smartphone with unique brand, model, storage, and battery specs
-
Inheritance Layer:
GamingSmartphone(inherits from Smartphone)- Additional Attributes: cooling_system, refresh_rate, gaming_mode
- Additional Methods: activate_gaming_mode()
- Polymorphism: Overrides get_info() method with gaming-specific information
- Encapsulation: Extends parent functionality while maintaining core smartphone features
✅ Create a program with vehicles that have the same action (move()) but define it differently
Vehicle Classes with Same Action (move()) - Different Behaviors:
- Car.move() →
"Tesla Model S is driving on the road 🚗" - Plane.move() →
"Boeing 737 is flying at 35000 feet ✈️" - Boat.move() →
"Ocean Explorer is sailing on the water ⛵" - Bicycle.move() →
"Mountain Bike is being pedaled 🚴"
- ✅ Same method name (
move()) across all vehicle classes - ✅ Different implementations - each class defines
move()uniquely - ✅ Runtime polymorphism - correct method called based on object type
- ✅ Uniform interface - all vehicles can be treated the same way in loops
- Save the code as
oop_assignment.py - Run the program:
python oop_assignment.py
🏗️ ASSIGNMENT 1: SMARTPHONE CLASS DEMO 🏗️
==================================================
Apple iPhone 15 - 256GB storage, 20h battery
Apple iPhone 15 is now ON
Instagram installed successfully!
TikTok installed successfully!
Apps installed: ['Instagram', 'TikTok']
ASUS ROG Phone 8 - 512GB storage, 18h battery, 165Hz display, Vapor Chamber cooling
ASUS ROG Phone 8 is now ON
Gaming mode activated! 165Hz refresh rate enabled
🎭 ASSIGNMENT 2: POLYMORPHISM CHALLENGE 🎭
==================================================
=== Polymorphism Demo ===
Tesla Model S - Max speed: 250 km/h
Movement: Tesla Model S is driving on the road 🚗
----------------------------------------
Boeing 737 - Max speed: 850 km/h
Movement: Boeing 737 is flying at 35000 feet ✈️
----------------------------------------
Ocean Explorer - Max speed: 45 km/h
Movement: Ocean Explorer is sailing on the water ⛵
----------------------------------------
Mountain Bike - Max speed: 30 km/h
Movement: Mountain Bike is being pedaled 🚴
----------------------------------------
- Created custom classes with meaningful attributes and methods
- Used constructors to initialize objects with unique values
- Implemented inheritance to extend class functionality
- Demonstrated polymorphism through method overriding
- Applied encapsulation principles
- Created a practical, real-world example
- Error Handling: Phone must be turned on before installing apps or activating gaming mode
- Method Chaining: Logical flow of operations (power on → use features)
- Polymorphism: Same interface (
move()) with different behaviors - Clean Code: Well-documented with docstrings and comments
- Real-world Applications: Practical examples students can relate to
- Python Version: Compatible with Python 3.6+
- Dependencies: None (uses only built-in Python features)
- Code Style: Follows PEP 8 guidelines
- Documentation: Comprehensive docstrings and comments
- Create a class -
Smartphoneclass created - Add attributes and methods - Multiple attributes (brand, model, storage, etc.) and methods (power_on, install_app, etc.)
- Use constructors -
__init__()method initializes each object with unique values - Add inheritance layer -
GamingSmartphoneinherits fromSmartphonewith additional features
- Create program with vehicles - 4 vehicle classes implemented
- Same action (
move()) - All vehicles havemove()method - Different definitions - Each class defines
move()uniquely:- Car: "Driving" 🚗
- Plane: "Flying"
✈️ - Boat: "Sailing" ⛵
- Bicycle: "Pedaling" 🚴
Created for PLP Python Week 5 Assignment
Demonstrates mastery of Object-Oriented Programming concepts in Python