-
Notifications
You must be signed in to change notification settings - Fork 0
/
showroom.py
136 lines (105 loc) · 3.4 KB
/
showroom.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class Node:
def __init__(self, nextNode, prevNode, data):
self.nextNode = nextNode
self.prevNode = prevNode
self.data = data
class LinkedList:
def __init__(self):
self.head = None
def add(self, node):
if self.head == None:
self.head = node
elif node.data.price < self.head.data.price:
node.nextNode = self.head
self.head.prevNode = node
self.head = node
else:
tempNode = self.head
while tempNode.nextNode != None:
if tempNode.nextNode.data.price > node.data.price:
break
tempNode = tempNode.nextNode
if tempNode.nextNode == None:
tempNode.nextNode = node
node.prevNode = tempNode
else:
node.nextNode = tempNode.nextNode
node.prevNode = tempNode
tempNode.nextNode.prevNode = node
tempNode.nextNode = node
def clean(self):
self.head = None
class Car:
def __init__(self, identification: int, name: str, brand: str, price: int, active: bool):
self.identification = identification
self.name = name
self.brand = brand
self.price = price
self.active = active
db = LinkedList()
def init(cars):
for i in cars:
add(i)
def add(car):
node = Node(None, None, car)
db.add(node)
def updateName(identification, name):
id = identification
tempNode = db.head
while tempNode.nextNode != None:
if tempNode.data.identification == id:
break
tempNode = tempNode.nextNode
if tempNode.nextNode == None and tempNode.data.identification != id:
return
else:
tempNode.data.name = name
def updateBrand(identification, brand):
id = identification
tempNode = db.head
while tempNode.nextNode != None:
if tempNode.data.identification == id:
break
tempNode = tempNode.nextNode
if tempNode.nextNode == None and tempNode.data.identification != id:
return
else:
tempNode.data.brand = brand
def activateCar(identification):
id = identification
tempNode = db.head
while tempNode.nextNode != None:
if tempNode.data.identification == id:
break
tempNode = tempNode.nextNode
if tempNode.nextNode == None and tempNode.data.identification != id:
return
else:
tempNode.data.active = True
def deactivateCar(identification):
id = identification
tempNode = db.head
while tempNode.nextNode != None:
if tempNode.data.identification == id:
break
tempNode = tempNode.nextNode
if tempNode.nextNode == None and tempNode.data.identification != id:
return
else:
tempNode.data.active = False
def getDatabaseHead():
return db.head
def getDatabase():
return db
def calculateCarPrice():
price = 0
tempNode = db.head
while tempNode.nextNode != None:
if tempNode.data.active == True:
price += tempNode.data.price
tempNode = tempNode.nextNode
if tempNode.nextNode == None and tempNode.data.active == True:
price += tempNode.data.price
return price
def clean():
db.clean()