Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

PLP Python Week 5 - Object-Oriented Programming Assignment

📚 Assignment Overview

This project completes the PLP Python Week 5 OOP assignment, demonstrating fundamental Object-Oriented Programming concepts through two main activities.

🏗️ Assignment 1: Design Your Own Class!

Requirements Fulfilled:

  1. Create a class representing anything you like - Smartphone class chosen
  2. Add attributes and methods to bring the class to life
  3. Use constructors to initialize each object with unique values
  4. Add an inheritance layer to explore polymorphism or encapsulation

Implementation:

  • 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

🎭 Activity 2: Polymorphism Challenge!

Requirements Fulfilled:

Create a program with vehicles that have the same action (move()) but define it differently

Implementation:

Vehicle Classes with Same Action (move()) - Different Behaviors:

  1. Car.move()"Tesla Model S is driving on the road 🚗"
  2. Plane.move()"Boeing 737 is flying at 35000 feet ✈️"
  3. Boat.move()"Ocean Explorer is sailing on the water ⛵"
  4. Bicycle.move()"Mountain Bike is being pedaled 🚴"

Polymorphism Achieved:

  • 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

🚀 How to Run

  1. Save the code as oop_assignment.py
  2. Run the program:
    python oop_assignment.py

📖 Sample Output

🏗️ 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 🚴
----------------------------------------

🎯 Learning Objectives Achieved

  • 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

💡 Key Features

  • 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

🔧 Technical Details

  • 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

🎯 Assignment Requirements Summary

Assignment 1: Design Your Own Class! 🏗️

  • Create a class - Smartphone class 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 - GamingSmartphone inherits from Smartphone with additional features

Activity 2: Polymorphism Challenge! 🎭

  • Create program with vehicles - 4 vehicle classes implemented
  • Same action (move()) - All vehicles have move() 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

About

This repository contains simple, beginner-friendly Python examples for PLP Week 5 that demonstrate core OOP concepts: a Device → Smartphone class (constructors, encapsulation, inheritance) and a Vehicle hierarchy showing polymorphic move() implementations.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages