Question: Create the following hierarchy with the following classes : Create a base class Vehicle . It should contain the following attributes: DEFAULT_FUEL_CONSUMPTION float (constant) fuel_consumption

 Create the following hierarchy with the following classes: Create a base

Create the following hierarchy with the following classes:

Create a base class Vehicle. It should contain the following attributes:

  • DEFAULT_FUEL_CONSUMPTION float (constant)
  • fuel_consumption float
  • fuel float
  • horse_power int
  • A public constructor which accepts (fuel, horse_power) and set the default fuel consumption on the attribute fuel_consumption

The class should have the following methods:

  • drive(kilometers)
    • The drive method should have a functionality to reduce the fuel based on the travelled kilometers and fuel consumption. Keep in mind that you can drive the vehicle only if you have enough fuel to finish the driving.

The default fuel consumption for Vehicle is 1.25. Some of the classes have different default fuel consumption:

  • SportCar DEFAULT_FUEL_CONSUMPTION = 10
  • RaceMotorcycle DEFAULT_FUEL_CONSUMPTION = 8
  • Car DEFAULT_FUEL_CONSUMPTION = 3

Test Code vehicle = Vehicle(50, 150) print(Vehicle.DEFAULT_FUEL_CONSUMPTION) print(vehicle.fuel) print(vehicle.horse_power) print(vehicle.fuel_consumption) vehicle.drive(100) print(vehicle.fuel) family_car = FamilyCar(150, 150) family_car.drive(50) print(family_car.fuel) family_car.drive(50) print(family_car.fuel) print(family_car.__class__.__bases__[0].__name__)

Vehicle Motorcycle Car RaceMotorcycle Cross Motorcycle FamilyCar SportCar Vehicle Motorcycle Car RaceMotorcycle Cross Motorcycle FamilyCar SportCar

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!