Question
[PYTHON] In class, we learned how inheritance allows us to create a general class first then later extend it to more specialized classes. Imagine you
[PYTHON]
In class, we learned how inheritance allows us to create a general class first
then later extend it to more specialized classes.
Imagine you run a car dealership. You sell several types of vehicles, including cars and trucks. To
set apart from the competition, you determine the price of a vehicle in you lot as $4,000number
of wheels a vehicle has. You also buy vehicles. You offer a flat rate - 10% of the miles driven on
the vehicle. The flat rates are: for cars $7,500, for trucks: $9,000
Your current sales system has a Car and a Truck class. Identify common attributes and methods
among those classes, and using the OOP principle of inheritance, create the parent class Vehicle.
The classes Car and Truck will inherit everything from Vehicle. (code available in your starter
code)
The functionality of the program should not change. Do not change any method name. Remember,
a parent class contains all attributes and methods common to the child classes.
class Car: def -init-(self, self.wheels-wheels self-miles miles self.ma ke = make self.mode1 model self-year = year self.gear = gear self.color = color self.sold on = False self. flat rate 7500 wheels, miles, make, model, year, gear, color): def sell (self) if self. sold on True : print("This item has been sold") else: self. sold on = True def sale_price (self) if self.sold on: return 0.0 # vehicle already sold return 4000 *self.wheels def purchase_price (self): return self.flat_rate.10 self.miles) def getDescription (self) sale_price-self.sale_price () return "(,miles >>> ".format (self.make, self.model, self.year, self.color, self.miles, sale price) class Truck: def _init (self. seats, wheels, miles, make, model, year) self.seats-seats self.wheels = wheels self.miles miles self.makemake self.mode 1 = model self-year = year self.sold on = False self. flat rate 9000 def sell (self): if self. sold on == True : print ("This item has been sold") else: self. sold on = True def sale price (self): if self.sold_on: return 0.0 # vehicle already sold return 4000 *self.wheels def purchase price (self) return self.flat rate-.10 self.miles) def getDescription (self) sale price=self.sale price() return " , miles seats >>> $". format (self.make, self.model, self.year,self.miles, self.seats, sale_price)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started