Skip to content

paulmbui20/Python-OOP-Projects-PLP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python OOP Projects - PLP πŸŽ“

Welcome to my Python Object-Oriented Programming assignments repository! This project showcases my understanding of core OOP concepts through practical implementations.

πŸ“Œ Repository Information

Repository: Python-OOP-Projects-PLP
Author: Paul Mbui
Course: PLP - Python Programming
Topic: Object-Oriented Programming (OOP)

πŸ“š What's Inside

This repository contains two comprehensive assignments that demonstrate mastery of OOP principles:

  1. Assignment 1: Superhero Management System
  2. Assignment 2: Transportation System (Polymorphism Challenge)

πŸš€ Getting Started

Prerequisites

  • Python 3.6 or higher installed on your system
  • Basic understanding of Python syntax
  • A code editor (VS Code, PyCharm, or any text editor)

Installation & Setup

  1. Clone the repository
git clone https://github.com/paulmbui20/Python-OOP-Projects-PLP.git
cd Python-OOP-Projects-PLP
  1. Verify Python installation
python --version
  1. Run the assignments
# Run Assignment 1
python assignment1.py

# Run Assignment 2
python assignment2.py

πŸ“– Assignment Details

Assignment 1: Superhero Management System πŸ¦Έβ€β™‚οΈ

A comprehensive class-based system for managing superheroes with different abilities and characteristics.

Features Implemented:

  • βœ… Custom class creation (Superhero)
  • βœ… Constructor implementation with instance variables
  • βœ… Multiple attributes (name, power, energy, health)
  • βœ… Various methods (use_power, rest, show_stats, take_damage)
  • βœ… Inheritance: FlyingHero and SpeedsterHero classes
  • βœ… Encapsulation: Private health attribute (__health)
  • βœ… Polymorphism: Different implementations of use_power() method

Classes Structure:

Superhero (Base Class)
β”œβ”€β”€ FlyingHero (Can fly at altitude)
└── SpeedsterHero (Super speed abilities)

Key Methods:

  • use_power() - Uses the hero's special ability
  • rest() - Recovers energy
  • show_stats() - Displays current statistics
  • take_damage() - Handles damage with encapsulation
  • get_health() - Getter method for private health attribute

Example Usage:

# Create a flying superhero
hero = FlyingHero("Sky Falcon", "Wind Blast", 90, 500)
hero.show_stats()
hero.fly()
hero.use_power()
hero.rest()

Edge Cases Handled:

  • Negative damage values
  • Energy depletion (can't use powers when tired)
  • Maximum energy cap (100)
  • Health reaching zero (defeat scenario)
  • Rest when already at full energy

Assignment 2: Transportation System πŸš—βœˆοΈπŸš’

A polymorphic demonstration featuring various modes of transportation, each with unique movement behaviors.

Features Implemented:

  • βœ… Base Vehicle class with common interface
  • βœ… Multiple vehicle types with inheritance
  • βœ… Polymorphism: Same move() method, different behaviors
  • βœ… Vehicle-specific methods and attributes
  • βœ… State management (moving/stopped)

Vehicle Types:

  1. Car πŸš— - Drives on roads, can honk, needs fuel
  2. Plane ✈️ - Flies through the sky, takes off and lands
  3. Boat 🚀 - Sails on water, has anchor, carries passengers
  4. Bicycle 🚴 - Pedals along, has gears, rings bell
  5. Train πŸš‚ - Runs on tracks, blows whistle

Polymorphism in Action:

vehicles = [Car("Sports Car"), Plane("Jet"), Boat("Cruiser")]

# Same method name, different behaviors!
for vehicle in vehicles:
    vehicle.move()

# Output:
# πŸš— Sports Car is driving on the road! Vroom vroom!
# ✈️ Jet is flying through the sky at 10000 feet!
# 🚀 Cruiser is sailing across the water! Splash splash!

Unique Features per Vehicle:

Car:

  • honk() - Makes horn sound
  • refuel() - Adds fuel
  • Fuel management system

Plane:

  • takeoff() - Launches into air
  • land_plane() - Returns to ground
  • Altitude tracking

Boat:

  • anchor() - Drops anchor to stop
  • board_passengers() - Adds passengers
  • Passenger counting

Bicycle:

  • change_gear() - Shifts gears
  • ring_bell() - Rings bicycle bell
  • Gear validation

Train:

  • blow_whistle() - Sounds train whistle
  • Multiple cars attribute

Edge Cases Handled:

  • Empty vehicle names (defaults to "Unknown Vehicle")
  • Negative passenger counts
  • Invalid gear numbers
  • Out of fuel scenarios
  • Already stopped/already moving states

🎯 OOP Concepts Demonstrated

1. Classes and Objects

Creating blueprints (classes) and instances (objects) with specific characteristics.

2. Constructors (__init__)

Initializing objects with unique values using the constructor method.

3. Instance Variables

Each object maintains its own state with unique attribute values.

4. Methods

Functions that define object behaviors and actions.

5. Inheritance πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦

Child classes inherit attributes and methods from parent classes:

  • FlyingHero and SpeedsterHero inherit from Superhero
  • All vehicle types inherit from Vehicle

6. Polymorphism πŸ¦„

Same method name produces different behaviors:

  • use_power() works differently for each hero type
  • move() is unique for each vehicle type

7. Encapsulation πŸ”

Private attributes protect internal data:

  • __health in Superhero class
  • Accessed only through getter methods

πŸ” Code Quality Features

Error Handling

  • Input validation for edge cases
  • Checking for negative values
  • Range validation (gears, fuel, energy)
  • Empty string handling

Code Organization

  • Clear class hierarchies
  • Logical method grouping
  • Descriptive variable names
  • Comprehensive comments

Testing

  • Main function demonstrations
  • Multiple test scenarios
  • Edge case verification
  • Polymorphism showcases

πŸ“ Learning Outcomes

Through these assignments, I've gained practical experience with:

βœ… Class Design: Structuring classes with appropriate attributes and methods
βœ… Inheritance Planning: Creating logical parent-child relationships
βœ… Polymorphism Implementation: Using method overriding effectively
βœ… Encapsulation Practice: Protecting data with private attributes
βœ… Code Reusability: Reducing repetition through inheritance
βœ… Real-world Modeling: Translating real objects into code structures
βœ… Edge Case Handling: Making robust, error-resistant programs


πŸ€” Challenges & Solutions

Challenge 1: Understanding Private Attributes

Problem: Initially confused about when to use __ prefix
Solution: Learned that private attributes protect sensitive data from external modification

Challenge 2: Method Overriding

Problem: Wasn't sure if child class methods completely replace parent methods
Solution: Discovered that child methods override parent methods, but super() can call parent version

Challenge 3: Polymorphism Implementation

Problem: Making sure all subclasses implement required methods correctly
Solution: Tested each class individually, then together in a list to verify polymorphic behavior

Challenge 4: Edge Case Testing

Problem: Programs crashed with unexpected inputs
Solution: Added validation checks before processing values (negative numbers, empty strings, etc.)


πŸ’‘ Key Takeaways

  1. OOP makes code more organized - Related data and functions stay together in classes
  2. Inheritance reduces repetition - Common features go in parent class
  3. Polymorphism adds flexibility - Same interface, different implementations
  4. Encapsulation protects data - Private attributes prevent unwanted changes
  5. Planning is important - Think about class structure before coding

πŸ› οΈ Technologies Used

  • Language: Python 3.x
  • Paradigm: Object-Oriented Programming
  • Concepts: Classes, Objects, Inheritance, Polymorphism, Encapsulation

πŸ“‚ Project Structure

Python-OOP-Projects-PLP/
β”‚
β”œβ”€β”€ assignment1.py          # Superhero Management System
β”œβ”€β”€ assignment2.py          # Transportation System
└── README.md              # Project documentation (this file)

🚦 Running the Code

Expected Output for Assignment 1:

The program will:

  1. Create three different types of heroes
  2. Demonstrate each hero's unique abilities
  3. Show energy management and health system
  4. Display polymorphism with different power usage
  5. Test edge cases like exhaustion and damage

Expected Output for Assignment 2:

The program will:

  1. Create five different vehicle types
  2. Demonstrate polymorphic move() method
  3. Show unique features for each vehicle
  4. Test vehicle-specific methods
  5. Validate edge cases and error handling

πŸ“ˆ Future Improvements

Potential enhancements for these projects:

  • Add a battle system for superheroes
  • Implement hero team formations
  • Create a vehicle race simulation
  • Add fuel consumption rates for vehicles
  • Include weather effects on vehicle movement
  • Build a GUI interface using tkinter
  • Save hero/vehicle data to files
  • Add more vehicle types (Helicopter, Submarine, etc.)

🀝 Contributing

This is a learning project, but suggestions and feedback are welcome! If you spot any issues or have ideas for improvement:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

πŸ“§ Contact

Paul Mbui
GitHub: @paulmbui20

Feel free to reach out if you have questions about the code or want to discuss OOP concepts!


πŸ“„ License

This project is created for educational purposes as part of the PLP Python Programming course.


πŸ™ Acknowledgments

  • PLP Academy for the comprehensive Python OOP curriculum
  • Course instructors for clear explanations and examples
  • Fellow students for collaborative learning

πŸ“š Additional Resources

Want to learn more about OOP in Python? Check out:


Last Updated: October 4, 2025

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages