-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathCar info.py
76 lines (59 loc) · 2.29 KB
/
Car info.py
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
from enum import Enum
class CarType(Enum):
SEDAN = 1
SUV = 2
BAKKIE = 3
class Fuel(Enum):
DIESEL = 1
PETROL = 2
class Car:
def __init__(self, model_year, type, price_per_day, fuel):
self.__model_year = model_year
self.__type = type
self.__price_per_day = price_per_day
self.__fuel = fuel
def get_type(self):
return self.__type
def get_price_per_day(self):
return self.__price_per_day
def get_model_year(self):
return self.__model_year
def __str__(self):
return '['+self.__model_year + ', ' + str(self.__type)+']'
class CompanyX:
def __init__(self):
self.cars = []
def add_car(self, car):
self.cars.append(car)
def is_there_a_specific_type_of_car(self, type):
for car in self.cars:
if car.get_type() == type:
return True
return False
def cheapest_car(self) -> Car:
cheapest = self.cars[0]
for i in range(1,len(self.cars)):
if self.cars[i].get_price_per_day()<cheapest.get_price_per_day():
cheapest = self.cars[i]
return cheapest
def how_many_car_from_specific_year_are_available(self, year):
counter = 0
for car in self.cars:
if car.get_model_year()==year:
counter += 1
return counter
if __name__ == '__main__':
company = CompanyX()
car1 = Car('2010', CarType.SEDAN, 25.0, Fuel.DIESEL)
car2 = Car('2011', CarType.SEDAN, 22.0, Fuel.PETROL)
car3 = Car('2010', CarType.BAKKIE, 35.0, Fuel.DIESEL)
company.add_car(car1)
company.add_car(car2)
company.add_car(car3)
print ('Is there a bakkie: ', company.is_there_a_specific_type_of_car(CarType.BAKKIE))
print ('Is there a SUV: ', company.is_there_a_specific_type_of_car(CarType.SUV))
print ('Is there a sedan: ', company.is_there_a_specific_type_of_car(CarType.SEDAN))
print ('The cheapest car is ', company.cheapest_car())
print ('Total of cars from 2010: ', company.how_many_car_from_specific_year_are_available('2010'))
print ('Total of cars from 2011: ', company.how_many_car_from_specific_year_are_available('2011'))
print ('Total of cars from 2012: ', company.how_many_car_from_specific_year_are_available('2012'))