Guest User

Untitled

a guest
Jan 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. # the vehicle class
  2. # a vehicle has a year, make, and model
  3. # a vehicle is instantiated with a make and model
  4.  
  5. class Vehicle(object):
  6.  
  7. def __init__(self, make, model):
  8. self.year = year
  9. self.make = make
  10. self.model = model
  11.  
  12. # acessor for the year
  13. @property
  14. def year(self):
  15. return self._year
  16.  
  17. #mutator for the year
  18. @year.setter
  19. def year(self, year):
  20. if (year >= 2000 and year <= 2018):
  21. self._year = year
  22.  
  23. #acessor for make
  24. @property
  25. def make(self):
  26. return self._make
  27.  
  28. #mutator for make
  29. @make.setter
  30. def make(self, make):
  31. self._make = make
  32.  
  33. #acessor for model
  34. @property
  35. def model(self):
  36. return self._model
  37.  
  38. #mutator for model
  39. @model.setter
  40. def model(self, model):
  41. self._model = model
  42.  
  43. # the truck class
  44. # a truck is a vehicle
  45. # a truck is instantiated with a make and model
  46. class Truck(Vehicle):
  47. def __init__(self, make, model):
  48. Vehicle.__init__(self, make, model)
  49. self.make = "Dodge"
  50. self.model = "Ram"
  51.  
  52. # the car class
  53. # a car is a vehicle
  54. # a car is instantiated with a make and model
  55.  
  56. class Car(Vehicle):
  57. def __init__(self, make, model):
  58. Vehicle.__init__(self, make, model)
  59. self.make = "Honda"
  60. self.model = "Civic"
  61.  
  62. # the Dodge Ram class
  63. # a Dodge Ram is a truck
  64. # a Dodge Ram is instantiated with a year
  65. # all Dodge Rams have the same make and model
  66.  
  67. class DodgeRam(Vehicle):
  68. def __init__(self, year):
  69. Vehicle.__init__(self, make, model)
  70. self.year = 2000
  71. Vehicle.year
  72. # the Honda Civic class
  73. # a Honda Civic is a car
  74. # a Honda Civic is instantiated with a year
  75. # all Honda Civics have the same make and model
  76.  
  77. class HondaCivic(Vehicle):
  78. def __init__(self, year):
  79. Vehicle.__init__(self, make, model)
  80. self.year = 2000
  81.  
  82.  
  83. # ***DO NOT MODIFY OR REMOVE ANYTHING BELOW THIS POINT!***
  84. # the main part of the program
  85. ram = DodgeRam(2016)
  86. print ram
  87.  
  88. civic1 = HondaCivic(2007)
  89. print civic1
  90.  
  91. civic2 = HondaCivic(1999)
  92. print civic2
  93.  
  94. #This is the output of the program
  95. #2016 Dodge Ram
  96. #2007 Honda Civic
  97. #2000 Honda Civic
Add Comment
Please, Sign In to add comment