Question

I NEED A CORRECT ANSWER THIS TIME PLEASE.THIS IS MY fourth TIME POSTING THIS QUESTION (Inheritance)...

I NEED A CORRECT ANSWER THIS TIME PLEASE.THIS IS MY fourth TIME POSTING THIS QUESTION (Inheritance) Please write a general class named Vehicle which contains make, model, color, year, mileage, weight and type information. Using the inheritance please write another class for gas vehicle (GasVehicle) and electric vehicles (ElectricVehicle). The GasVehicle class has an attribute named fuel tank capacity. However, the ElectricVehicle class has an energy storage in kwh. All the above classes must contains a method named print_vehicle_info which prints the vehicle information. This method must print different information for different classes. Please write a python script named q2.py which contains all the above classes, then create an instance of gas and electric vehicles and call the print_behicle_info method for each instance. $ python q2.py Vehicle Type: Gas Make: Honda Model: Accord Color: white Year: 2018 Miles driven: 5000 Weight: 3000 Fuel capacity (gallons): 90 Vehicle Type: Electric Make: Tesla Model: S Color: white Year: 2018 Miles driven: 2000 Weight: 4000 Energy Storage (Kwh): 1000

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is your code

class Vehicle(object): # no instance of this class should be created

def __init__(self, typ, make, model, color, year, miles, weight):

self.typ = typ

self.make = make

self.model = model

self.color = color.lower()

self.year = year

self.miles = miles

self.weight = weight

def print_vehicle_info(self):

print('Vehicle Type: ' + str(self.typ))

print('Make: ' + str(self.make))

print('Model: ' + str(self.model))

print('Color: ' + str(self.color))

print('Year: ' + str(self.year))

print('Miles driven: ' + str(self.miles))

print('Weight: '+ str(self.weight))

class GasVehicle(Vehicle):

def __init__(self, fuel_tank, *args):

self.fuel_tank = fuel_tank

Vehicle.__init__(self, *args)

def print_vehicle_info(self):

Vehicle.print_vehicle_info(self)

print('Fuel capacity (gallons): ' + str(self.fuel_tank))

class ElectricVehicle(Vehicle):

def __init__(self, energy_storage, *args):

self.energy_storage = energy_storage

Vehicle.__init__(self, *args)

def print_vehicle_info(self):

Vehicle.print_vehicle_info(self)

print('Energy Storage (Kwh): ' + str(self.energy_storage))

vehicle=GasVehicle(90,"Gas","Honda","Accord","white",2018,5000,3000)

vehicle.print_vehicle_info()

print("\n")

vehicle1=ElectricVehicle(1000,"Electric","Tesla","S","white",2018,2000,4000)

vehicle1.print_vehicle_info()

class Vehicle (object) : # no instance of this class should be created def init_ _(self, typ, make, model, color, year, miles

Output

Vehicle Type: Gas
Make: Honda
Model: Accord
Color: white
Year: 2018
Miles driven: 5000
Weight: 3000
Fuel capacity (gallons): 90


Vehicle Type: Electric
Make: Tesla
Model: S
Color: white
Year: 2018
Miles driven: 2000
Weight: 4000
Energy Storage (Kwh): 1000
Add a comment
Know the answer?
Add Answer to:
I NEED A CORRECT ANSWER THIS TIME PLEASE.THIS IS MY fourth TIME POSTING THIS QUESTION (Inheritance)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA PROGRAMING - TESTING CLASSES AND INHERITANCE Create two classes - a vehicle class and gasguzzler...

    JAVA PROGRAMING - TESTING CLASSES AND INHERITANCE Create two classes - a vehicle class and gasguzzler class. Neither classes have I/O. Use a test class as well. Vehicle class has methods and properties that all vehicles have. This class has two properties - speed (rate of travel in miles per hour) and weight (in pounds) Vehicle Class Public Methods: Vehicle objects can be constructed 2 different ways: by specifying the weight and the speed, or by specifying the weight only...

  • 1. Extending the answer from Python HW #7 for question #1, write the following python code...

    1. Extending the answer from Python HW #7 for question #1, write the following python code to expand on the Car class. Include the python code you developed when answering HW #7. Add class “getter” methods to return the values for model, color, and MPG Add class “setter” methods to change the existing values for model, color, and MPG. The value to be used in the methods will be passed as an input argument. Add class method that will calculate...

  • in java Create a new project named, firstInitialLastNameCS185EOS. Create and use a class that prints a title.   Create a use a menu that contains the following items, and calls corresponding methods...

    in java Create a new project named, firstInitialLastNameCS185EOS. Create and use a class that prints a title.   Create a use a menu that contains the following items, and calls corresponding methods that do the tasks the menu describes. Use classes when they're appropriate. Keep the driver class as simple as possible. Give each class, method and property simple, descriptive names using Hungarian notation. Square a number Simply pass a decimal-type number to the object that does this task. Process its...

  • Python 3 Problem: I hope you can help with this please answer the problem using python...

    Python 3 Problem: I hope you can help with this please answer the problem using python 3. Thanks! Code the program below . The program must contain and use a main function that is called inside of: If __name__ == “__main__”: Create the abstract base class Vehicle with the following attributes: Variables Methods Manufacturer Model Wheels TypeOfVehicle Seats printDetails() - ABC checkInfo(**kwargs) The methods with ABC next to them should be abstracted and overloaded in the child class Create three...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • C# - Inheritance exercise I could not firgure out why my code was not working. I...

    C# - Inheritance exercise I could not firgure out why my code was not working. I was hoping someone could do it so i can see where i went wrong. STEP 1: Start a new C# Console Application project and rename its main class Program to ZooPark. Along with the ZooPark class, you need to create an Animal class. The ZooPark class is where you will create the animal objects and print out the details to the console. Add the...

  • Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the...

    Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the call to addFuel in the main program with a call to the accessor and mutator for the fuel amount to achieve the same effect (add 5 gallons of fuel to the existing fuel in the Toyota Camry). Test your program again to make sure it works and produces the same output. Part 2: Add functions to remove duplicate code * In the main program,...

  • HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE...

    HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE PROGRAM RUNS. Task 1: Enforcing const-ness throughout Your first job will be to go through all of the code and decide which functions should be declared const. You should find several places throughout the program where this makes sense. We will also make the id data member in the Customer class const , as once a customer has been created their ID will never...

  • Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in...

    Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in interesting ways. Now you’ll get a chance to use more of what objects offer, implementing inheritance and polymorphism and seeing them in action. You’ll also get a chance to create and use abstract classes (and, perhaps, methods). After this project, you will have gotten a good survey of object-oriented programming and its potential. This project won’t have a complete UI but will have a...

  • It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #inclu...

    It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #include "File.h" // Constructor of File that takes File name and type as arguments File::File(string type, string name) {    this->type = type;    this->name = name; } //returns the type. string File::getType() {    return type; } //returns the name of file. string File::getName() {    return name; } File.h #ifndef __FILE_H__ #define...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT