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
6 changes: 6 additions & 0 deletions .ipynb_checkpoints/Bus-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
14 changes: 14 additions & 0 deletions .ipynb_checkpoints/Car-checkpoint.py
Original file line number Diff line number Diff line change
@@ -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!"
15 changes: 15 additions & 0 deletions .ipynb_checkpoints/Motorcycle-checkpoint.py
Original file line number Diff line number Diff line change
@@ -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!"
14 changes: 14 additions & 0 deletions .ipynb_checkpoints/Truck-checkpoint.py
Original file line number Diff line number Diff line change
@@ -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!"
19 changes: 19 additions & 0 deletions .ipynb_checkpoints/Vehicle-checkpoint.py
Original file line number Diff line number Diff line change
@@ -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.")
68 changes: 68 additions & 0 deletions .ipynb_checkpoints/usage-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
21 changes: 21 additions & 0 deletions Bus.py
Original file line number Diff line number Diff line change
@@ -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!"