-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05 A Simple Vehicle Class...Reloaded.py
More file actions
98 lines (79 loc) · 2.36 KB
/
05 A Simple Vehicle Class...Reloaded.py
File metadata and controls
98 lines (79 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#########################################################
# Name: Brandon Fortes
# Date: January 30, 2024
# Description: Implements vehicle, truck and car, and Honda Civic and Dodge Ram classes using inheritance
#########################################################
# the vehicle class
# a vehicle has a year, make, and model
# a vehicle is instantiated with a make and model
class Vehicle:
def __init__(self, make, model):
self.year = 2000
self.make = make
self.model = model
@property
def year(self):
return self._year
@property
def make(self):
return self._make
@property
def model(self):
return self._model
@year.setter
def year(self, value):
value = self.year if value < 2000 else value
value = self.year if value > 2018 else value
self._year = value
@make.setter
def make(self, value):
self._make = value
@model.setter
def model(self, value):
self._model = value
def __str__(self):
return f"{self.year} {self.make} {self.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):
super().__init__(self.make, self.model)
self.make = make
self.model = model
# 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):
super().__init__(self.make, self.model)
self.make = make
self.model = model
# 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(Truck):
make = "Dodge"
model = "Ram"
def __init__(self, year):
super().__init__(self.make, self.model)
self.year = 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(Car):
make = "Honda"
model = "Civic"
def __init__(self, year):
super().__init__(self.make, self.model)
self.year = year
# ***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)