From 5bdbac33d3d38f22ffbab057123f97faae8876f6 Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Tue, 26 Nov 2024 15:15:02 -0500 Subject: [PATCH] Added Bus class to Vehicle.py --- Vehicle.py | 16 +++++++++++++++- usage.ipynb | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Vehicle.py b/Vehicle.py index 260f28e..6a33be4 100644 --- a/Vehicle.py +++ b/Vehicle.py @@ -16,4 +16,18 @@ def fuel_up(self): return "Full tank" def brake(self): - print("Braking the car.") + print("Braking the vehicle.") + + +class Bus(Vehicle): + def __init__(self, brand, model, year, seating_capacity): + super().__init__(brand, model, year) + self.seating_capacity = seating_capacity + + def display_info(self): + """Override display_info to include seating capacity.""" + return f"{super().display_info()} with seating capacity of {self.seating_capacity} passengers" + + def capacity_info(self): + """Specific method for buses.""" + return f"The bus can seat up to {self.seating_capacity} passengers." \ No newline at end of file diff --git a/usage.ipynb b/usage.ipynb index f3a90ee..4487d98 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 Vehicle import Bus" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -23,9 +24,12 @@ "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", + "Mercedes Citaro (2023) with seating capacity of 50 passengers\n", + "The bus can seat up to 50 passengers.\n", "Honk honk!\n", "Meep meep!\n", - "HOOOOONK!\n" + "HOOOOONK!\n", + "Beep beep!\n" ] } ], @@ -33,14 +37,19 @@ "car = Car(\"Toyota\", \"Camry\", 2022, 4)\n", "motorcycle = Motorcycle(\"Harley-Davidson\", \"Iron 883\", 2021, False)\n", "truck = Truck(\"Volvo\", \"FH16\", 2020, 25)\n", + "city_bus = Bus(\"Mercedes\", \"Citaro\", 2023, 50)\n", "\n", "print(car.display_info())\n", "print(motorcycle.display_info())\n", "print(truck.display_info())\n", + "print(city_bus.display_info())\n", + "print(city_bus.capacity_info()) \n", + "\n", "\n", "print(car.honk())\n", "print(motorcycle.honk())\n", - "print(truck.honk())" + "print(truck.honk())\n", + "print(city_bus.honk()) " ] } ], @@ -60,7 +69,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.5" + "version": "3.13.0" } }, "nbformat": 4,