Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cycle.py
Original file line number Diff line number Diff line change
@@ -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!"
7 changes: 6 additions & 1 deletion Truck.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -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"
24 changes: 16 additions & 8 deletions usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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"
},
Expand All @@ -60,7 +68,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down