Solution: Vehicle Management System
Review the solution for the vehicle management system.
We'll cover the following...
Solution
Let’s explore the solution to the problem of the vehicle management system.
Press + to interact
# Base Classclass Vehicle:def __init__(self, make, model):self.make = makeself.model = modeldef display_info(self):print("Subclasses should implement this method")# Derived Class Carclass Car(Vehicle):def __init__(self, make, model, num_doors):super().__init__(make, model)self.num_doors = num_doorsdef display_info(self):print(f"Car - Make: {self.make}, Model: {self.model}, Number of doors: {self.num_doors}")# Derived Class Motorcycleclass Motorcycle(Vehicle):def __init__(self, make, model, type_of_handlebars):super().__init__(make, model)self.type_of_handlebars = type_of_handlebarsdef display_info(self):print(f"Motorcycle - Make: {self.make}, Model: {self.model}, Type of Handlebars: {self.type_of_handlebars}")# Derived Class Truckclass Truck(Vehicle):def __init__(self, make, model, payload_capacity):super().__init__(make, model)self.payload_capacity = payload_capacitydef display_info(self):print(f"Truck - Make: {self.make}, Model: {self.model}, Payload Capacity: {self.payload_capacity}kg")# Main Programdef main():vehicles = [Car("Toyota", "Corolla", 4),Motorcycle("Yamaha", "MT-07", "Sport"),Truck("Ford", "F-150", 1000)]for vehicle in vehicles:vehicle.display_info()main()
Explanation
Here’s the explanation of the code: ...