-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
148 lines (131 loc) · 5.39 KB
/
classes.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
137
138
139
140
141
142
143
144
145
146
147
class Lokomotyvas:
def __init__(self,mase,maxMase):
self.mase = mase
self.maxMase = maxMase
@property
def mase(self):
return self._mase
@property
def maxMase(self):
return self._maxMase
@mase.setter
def mase(self,v):
if (v > 0)and(type(v)==int):
self._mase = v
else:
self._mase = 1
print("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("Mase turi buti skaicius ir daugiau uz 0!")
print("Nustatyta pradine reiksme 1!")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
@maxMase.setter
def maxMase(self,v):
if (v > 0)and(type(v)==int):
self._maxMase = v
else:
self._maxMase = 2
print("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("Max mase turi buti skaicius ir daugiau uz 0!")
print("Nustatyta pradine reiksme 2!")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
def __add__(self,other):
return(self._mase+other._mase,self._maxMase+other._maxMase)
def __sub__(self,other):
return(self._mase-other._mase,self._maxMase-other._maxMase)
def __repr__(self):
return "(Mase: %d, Max mase: %d)"%(self._mase,self._maxMase)
def __str__(self):
return "Mase: %i, Max mase: %i" %(self._mase,self._maxMase)
class Vagonas:
def __init__(self,mase,maxMase,krovinioMase,nr):
self.mase = mase
self.maxMase = maxMase
self.krovinioMase = krovinioMase
self.nr = nr
@property
def mase(self):
return self._mase
@property
def maxMase(self):
return self._maxMase
@property
def krovinioMase(self):
return self._krovinioMase
@property
def nr(self):
return self._nr
@mase.setter
def mase(self,v):
if (v > 0)and(type(v)==int):
self._mase = v
else:
self._mase = 1
print("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("Mase turi buti skaicius ir daugiau uz 0!")
print("Nustatyta pradine reiksme 1!")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
@maxMase.setter
def maxMase(self,v):
if (v > 0)and(type(v)==int):
self._maxMase = v
else:
self._maxMase = 2
print("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("Max mase turi buti skaicius ir daugiau uz 0!")
print("Nustatyta pradine reiksme 2!")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
@krovinioMase.setter
def krovinioMase(self,v):
if (v > 0)and(type(v)==int):
self._krovinioMase = v
else:
self._krovinioMase = 1
print("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("Krovinio mase turi buti skaicius ir daugiau uz 0!")
print("Nustatyta pradine reiksme 1!")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
@nr.setter
def nr(self,v):
if (v > 0)and(type(v)==int):
self._nr = v
else:
self._nr = 1
print("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("Nr turi buti skaicius ir daugiau uz 0!")
print("Nustatyta pradine reiksme 1!")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
def __add__(self,other):
return(self._mase+other._mase,self._maxMase+other._maxMase)
def __repr__(self):
return "(Mase: %d, Max mase: %d, Krovinio mase: %d, Nr: %d)" %(self._mase,self._maxMase,self._krovinioMase,self._nr)
def __str__(self):
return "Mase: %i, Max mase: %i, Krovinio mase: %i, Nr: %i" %(self._mase,self._maxMase,self._krovinioMase,self._nr)
#Add ir Sub surusiuoja traukinius pagal laisva vieta arba visa vagonu ir lokomatyvu mase
class Traukinys:
def __init__(self,lok,vag,nr):
self.lok = lok
self.vag = vag
self.nr = nr
def __repr__(self):
return "(Lok: %s Vag: %s Traukinio Nr.: %s)" % (self.lok,self.vag,self.nr)
def __str__(self):
return "Lokomotyvo mase: %s,Vagono mase: %s, Traukinio nr.: %s" %(self.lok,self.vag,self.nr)
#1.Rusiuojant pagal mase suskaiciuoja bendra lokomatyvu ir vagonu mase ir isrusiuoja didejimo tvarka
def __add__(self,other):
lok_mase = self.lok._mase+other.lok._mase
vag_mase = self.vag._mase+other.vag._mase
mase = lok_mase + vag_mase
return mase
#2.Rusiuojant pagal laisva vieta pirmiausia suranda maksimalia vagonu ir lokomatyvu mase
# Tada is maksimalios mases atima vezama kroviniu mase ir randama atlikusi laisva vieta
def __sub__(self,other):
maxMaseVagono = self.vag._maxMase+other.vag._maxMase
maxMaseLokoloko = self.lok._maxMase+other.lok._maxMase
maxMase = maxMaseVagono + maxMaseLokoloko
krovinioMase = self.vag._krovinioMase + other.vag._krovinioMase
uzimtaMase = maxMase - krovinioMase
return uzimtaMase
def __len__(self):
return len(Traukinys)
def __bool__(self):
return False