diff --git a/Cycle.py b/Cycle.py new file mode 100644 index 0000000..4fb037c --- /dev/null +++ b/Cycle.py @@ -0,0 +1,14 @@ +from Vehicle import Vehicle + +class Cycle(Vehicle): + def __init__(self, brand, model, year, wheels): + super().__init__(brand, model, year) + self.wheels = wheels + + def display_info(self): + """Override the parent class method for a Cycle.""" + return f"Cycle: {self._brand}, Model: {self._model}, Wheels: {self.wheels} ({self._year})" + + def bell(self): + """Specific implementation for a cycle.""" + return "Ring! Ring!" diff --git a/Truck.py b/Truck.py index 44773a9..069a214 100644 --- a/Truck.py +++ b/Truck.py @@ -1,9 +1,10 @@ from Vehicle import Vehicle class Truck(Vehicle): - def __init__(self, brand, model, year, max_load): + def __init__(self, brand, model, year, max_load, truckHeight): super().__init__(brand, model, year) self.max_load = max_load + self.truckHeight = truckHeight def display_info(self): """Override the parent class method for a Truck.""" @@ -12,3 +13,7 @@ def display_info(self): def honk(self): """Specific implementation for a truck.""" return "HOOOOONK!" + + def heightLimit(self): + """Method for comparing truck's height to height restrictions in bridges/tunnels""" + return f"Truck height is {self.truckHeight}, and the height limit is 20" diff --git a/usage.ipynb b/usage.ipynb index f3a90ee..9363793 100644 --- a/usage.ipynb +++ b/usage.ipynb @@ -2,18 +2,19 @@ "cells": [ { "cell_type": "code", - "execution_count": 9, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from Car import Car\n", "from Motorcycle import Motorcycle\n", - "from Truck import Truck" + "from Truck import Truck\n", + "from Cycle import Cycle" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -23,30 +24,37 @@ "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", + "Cycle: Trek, Model: Mountain, Wheels: 2 (2022)\n", "Honk honk!\n", "Meep meep!\n", - "HOOOOONK!\n" + "HOOOOONK!\n", + "Truck height is 10, and the height limit is 20\n", + "Ring! Ring!\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", + "truck = Truck(\"Volvo\", \"FH16\", 2020, 25, 10)\n", + "cycle = Cycle(\"Trek\", \"Mountain\", 2022, 2)\n", "\n", "print(car.display_info())\n", "print(motorcycle.display_info())\n", "print(truck.display_info())\n", + "print(cycle.display_info())\n", "\n", "print(car.honk())\n", "print(motorcycle.honk())\n", - "print(truck.honk())" + "print(truck.honk())\n", + "print(truck.heightLimit())\n", + "print(cycle.bell())" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -60,7 +68,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.5" + "version": "3.12.4" } }, "nbformat": 4,