Exercise: Vehicle Management System
Implement the vehicle management system using OOP concept.
We'll cover the following
Problem statement
Let's suppose a company needs a vehicle management system to manage different types of vehicles. Each vehicle has common attributes and behaviors, but certain types of vehicles have specific behaviors. Implement the following classes and methods:
Vehicle (base class):
Attributes:
make
,model
Methods:
display_info()
, prints the make and model of the vehicle.
Car (derived class):
Inherits from:
Vehicle
Additional attributes:
num_doors
Overridden method:
display_info()
, prints the make, model, and number of doors.
Motorcycle (derived class):
Inherits from:
Vehicle
Additional attributes:
type_of_handlebars
Overridden method:
display_info()
, prints the make, model, and type of handlebars.
Truck (Derived Class):
Inherits from:
Vehicle
Additional attributes:
payload_capacity
Overridden method:
display_info()
, prints the make, model, and payload capacity.
The main function is already given. You need to create the classes, attributes, and methods based on the main function.
Coding challenge
Take some time to think about how many classes are created and identify their attributes and functions in the context of a vehicle management system. Ensure you account for all possible edge cases, such as invalid vehicle IDs or negative mileage. Pay attention to the relationships between classes, such as inheritance and composition. If you find yourself struggling, you can look at the solution review in the next lesson for guidance.
Good luck!
Get hands-on with 1400+ tech skills courses.