Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # the vehicle class
- # a vehicle has a year, make, and model
- # a vehicle is instantiated with a make and model
- class Vehicle(object):
- def __init__(self, make, model):
- self.year = year
- self.make = make
- self.model = model
- # acessor for the year
- @property
- def year(self):
- return self._year
- #mutator for the year
- @year.setter
- def year(self, year):
- if (year >= 2000 and year <= 2018):
- self._year = year
- #acessor for make
- @property
- def make(self):
- return self._make
- #mutator for make
- @make.setter
- def make(self, make):
- self._make = make
- #acessor for model
- @property
- def model(self):
- return self._model
- #mutator for model
- @model.setter
- def model(self, model):
- self._model = model
- # the truck class
- # a truck is a vehicle
- # a truck is instantiated with a make and model
- class Truck(Vehicle):
- def __init__(self, make, model):
- Vehicle.__init__(self, make, model)
- self.make = "Dodge"
- self.model = "Ram"
- # the car class
- # a car is a vehicle
- # a car is instantiated with a make and model
- class Car(Vehicle):
- def __init__(self, make, model):
- Vehicle.__init__(self, make, model)
- self.make = "Honda"
- self.model = "Civic"
- # the Dodge Ram class
- # a Dodge Ram is a truck
- # a Dodge Ram is instantiated with a year
- # all Dodge Rams have the same make and model
- class DodgeRam(Vehicle):
- def __init__(self, year):
- Vehicle.__init__(self, make, model)
- self.year = 2000
- Vehicle.year
- # the Honda Civic class
- # a Honda Civic is a car
- # a Honda Civic is instantiated with a year
- # all Honda Civics have the same make and model
- class HondaCivic(Vehicle):
- def __init__(self, year):
- Vehicle.__init__(self, make, model)
- self.year = 2000
- # ***DO NOT MODIFY OR REMOVE ANYTHING BELOW THIS POINT!***
- # the main part of the program
- ram = DodgeRam(2016)
- print ram
- civic1 = HondaCivic(2007)
- print civic1
- civic2 = HondaCivic(1999)
- print civic2
- #This is the output of the program
- #2016 Dodge Ram
- #2007 Honda Civic
- #2000 Honda Civic
Add Comment
Please, Sign In to add comment