From 34a25721d4043c058ff26d59fc873704e09bd217 Mon Sep 17 00:00:00 2001 From: Rahel-Chr Date: Sat, 30 Nov 2024 21:49:30 -0500 Subject: [PATCH] Added Bus class inheriting from Vehicle class --- .ipynb_checkpoints/Bus-checkpoint.py | 6 ++ .ipynb_checkpoints/Car-checkpoint.py | 14 +++++ .ipynb_checkpoints/Motorcycle-checkpoint.py | 15 +++++ .ipynb_checkpoints/Truck-checkpoint.py | 14 +++++ .ipynb_checkpoints/Vehicle-checkpoint.py | 19 ++++++ .ipynb_checkpoints/usage-checkpoint.ipynb | 68 +++++++++++++++++++++ Bus.py | 21 +++++++ 7 files changed, 157 insertions(+) create mode 100644 .ipynb_checkpoints/Bus-checkpoint.py create mode 100644 .ipynb_checkpoints/Car-checkpoint.py create mode 100644 .ipynb_checkpoints/Motorcycle-checkpoint.py create mode 100644 .ipynb_checkpoints/Truck-checkpoint.py create mode 100644 .ipynb_checkpoints/Vehicle-checkpoint.py create mode 100644 .ipynb_checkpoints/usage-checkpoint.ipynb create mode 100644 Bus.py diff --git a/.ipynb_checkpoints/Bus-checkpoint.py b/.ipynb_checkpoints/Bus-checkpoint.py new file mode 100644 index 0000000..363fcab --- /dev/null +++ b/.ipynb_checkpoints/Bus-checkpoint.py @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/.ipynb_checkpoints/Car-checkpoint.py b/.ipynb_checkpoints/Car-checkpoint.py new file mode 100644 index 0000000..9741b1f --- /dev/null +++ b/.ipynb_checkpoints/Car-checkpoint.py @@ -0,0 +1,14 @@ +from Vehicle import Vehicle + +class Car(Vehicle): + def __init__(self, brand, model, year, doors): + super().__init__(brand, model, year) + self.doors = doors + + def display_info(self): + """Override the parent class method for a Car.""" + return f"Car: {self._brand} {self._model}, {self.doors} doors ({self._year})" + + def honk(self): + """Specific implementation for a car.""" + return "Honk honk!" diff --git a/.ipynb_checkpoints/Motorcycle-checkpoint.py b/.ipynb_checkpoints/Motorcycle-checkpoint.py new file mode 100644 index 0000000..992790d --- /dev/null +++ b/.ipynb_checkpoints/Motorcycle-checkpoint.py @@ -0,0 +1,15 @@ +from Vehicle import Vehicle + +class Motorcycle(Vehicle): + def __init__(self, brand, model, year, has_sidecar): + super().__init__(brand, model, year) + self.has_sidecar = has_sidecar + + def display_info(self): + """Override the parent class method for a Motorcycle.""" + sidecar = "with sidecar" if self.has_sidecar else "without sidecar" + return f"Motorcycle: {self._brand} {self._model}, {sidecar} ({self._year})" + + def honk(self): + """Specific implementation for a motorcycle.""" + return "Meep meep!" diff --git a/.ipynb_checkpoints/Truck-checkpoint.py b/.ipynb_checkpoints/Truck-checkpoint.py new file mode 100644 index 0000000..44773a9 --- /dev/null +++ b/.ipynb_checkpoints/Truck-checkpoint.py @@ -0,0 +1,14 @@ +from Vehicle import Vehicle + +class Truck(Vehicle): + def __init__(self, brand, model, year, max_load): + super().__init__(brand, model, year) + self.max_load = max_load + + def display_info(self): + """Override the parent class method for a Truck.""" + return f"Truck: {self._brand} {self._model}, Max load: {self.max_load} tons ({self._year})" + + def honk(self): + """Specific implementation for a truck.""" + return "HOOOOONK!" diff --git a/.ipynb_checkpoints/Vehicle-checkpoint.py b/.ipynb_checkpoints/Vehicle-checkpoint.py new file mode 100644 index 0000000..260f28e --- /dev/null +++ b/.ipynb_checkpoints/Vehicle-checkpoint.py @@ -0,0 +1,19 @@ +class Vehicle: + def __init__(self, brand, model, year): + self._brand = brand + self._model = model + self._year = year + + def display_info(self): + """Abstract method to display vehicle info.""" + return f"{self._brand} {self._model} ({self._year})" + + def honk(self): + """A general honk sound for all vehicles.""" + return "Beep beep!" + + def fuel_up(self): + return "Full tank" + + def brake(self): + print("Braking the car.") diff --git a/.ipynb_checkpoints/usage-checkpoint.ipynb b/.ipynb_checkpoints/usage-checkpoint.ipynb new file mode 100644 index 0000000..f3a90ee --- /dev/null +++ b/.ipynb_checkpoints/usage-checkpoint.ipynb @@ -0,0 +1,68 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "from Car import Car\n", + "from Motorcycle import Motorcycle\n", + "from Truck import Truck" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Car: Toyota Camry, 4 doors (2022)\n", + "Motorcycle: Harley-Davidson Iron 883, without sidecar (2021)\n", + "Truck: Volvo FH16, Max load: 25 tons (2020)\n", + "Honk honk!\n", + "Meep meep!\n", + "HOOOOONK!\n" + ] + } + ], + "source": [ + "car = Car(\"Toyota\", \"Camry\", 2022, 4)\n", + "motorcycle = Motorcycle(\"Harley-Davidson\", \"Iron 883\", 2021, False)\n", + "truck = Truck(\"Volvo\", \"FH16\", 2020, 25)\n", + "\n", + "print(car.display_info())\n", + "print(motorcycle.display_info())\n", + "print(truck.display_info())\n", + "\n", + "print(car.honk())\n", + "print(motorcycle.honk())\n", + "print(truck.honk())" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Bus.py b/Bus.py new file mode 100644 index 0000000..6de144e --- /dev/null +++ b/Bus.py @@ -0,0 +1,21 @@ +from Vehicle import Vehicle + +class Bus(Vehicle): + def __init__(self, brand, model, year, seats): + super().__init__(brand, model, year) + self._seats = seats + + def display_info(self): + """Override method to display bus info with seat count.""" + return f"{self._brand} {self._model} ({self._year}) - Seats: {self._seats}" + + def honk(self): + """Override honk method with a louder sound for the bus.""" + return "HONK HOOONK!" + + def load_passengers(self, num_passengers): + """Simulate loading passengers into the bus.""" + if num_passengers <= self._seats: + return f"{num_passengers} passengers loaded." + else: + return f"Capacity reached!"