Ilom_uk

Broken Parcel Pre Release

Feb 5th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. MAXDIMS = 80.0
  2. MAXSUMDIMS = 200.0
  3. MAXWEIGHT = 10.0
  4. MINWEIGHT = 1.0
  5.  
  6. #F8 TO STEP DOWN A LINE!
  7.  
  8.  
  9. #-----------------------
  10. #CLASS [PARCEL]:
  11. class Parcel():
  12. def __init__(self):
  13. self.__weight = 0.0
  14. self.__height = 0.0
  15. self.__width = 0.0
  16. self.__depth = 0.0
  17. self.__price = 0.00
  18. self.__totalDims = 0.0
  19. self.__isValid = True
  20. self.__reasonsInvalid = []
  21.  
  22.  
  23. #GETTERS!
  24. def getWeight(self):
  25. return self.__weight
  26. def getHeight(self):
  27. return self.__height
  28. def getWidth(self):
  29. return self.__width
  30. def getDepth(self):
  31. return self.__depth
  32. def getPrice(self):
  33. return self.__price
  34. def getTotalDims(self):
  35. return self.__totalDims
  36. def getIsValid(self):
  37. return self.__isValid
  38. def getReasonsInvalid(self):
  39. return self.__reasonsInvalid
  40.  
  41. #PRINT ALL!
  42. def printAll(self):
  43. print("Weight:",self.__weight)
  44. print("Height:",self.__height)
  45. print("Width:",self.__width)
  46. print("Depth:",self.__depth)
  47. print("Price:",self.__price)
  48. print("Total Dimensions:",self.__totalDims)
  49. print("Is Valid?",self.__isValid)
  50. print("Reasons Invalid:",self.__reasonsInvalid)
  51.  
  52. #SETTERS!
  53. def setWeight(self):
  54. self.__weight = float(input("Input weight in kilograms:"))
  55. def setHeight(self):
  56. self.__height = float(input("Input height in centimetres:"))
  57. def setWidth(self):
  58. self.__width = float(input("Input width in centimetres:"))
  59. def setDepth(self):
  60. self.__depth = float(input("Input depth in centimetres:"))
  61. def setPrice(self):
  62. self.__price = float(input("Input price in pounds & pence:"))
  63. def setTotalDims(self):
  64. self.__totalDims = float(input("Input sum of dimensions in centimetres:"))
  65. def setIsValid(self):
  66. self.__isValid = bool(input("Input whether parcel is valid:"))
  67.  
  68. def setProperties(self):
  69. self.__weight = float(input("Input weight in kilograms:"))
  70. self.__height = float(input("Input height in centimetres:"))
  71. self.__width = float(input("Input width in centimetres:"))
  72. self.__depth = float(input("Input depth in centimetres:"))
  73.  
  74. #FUNCTIONS!
  75. def calcTotalDims(self):
  76. self.__totalDims = self.__height + self.__width + self.__depth
  77. def calcPrice(self):
  78. if len(self.__reasonsInvalid) != 0:
  79. self.__price = 0.00
  80. else:
  81. self.__price = 5.00
  82. if (self.__weight > 5):
  83. weightDiff = self.__weight - 5
  84. extraPrice = weightDiff
  85. self.__price = self.__price + extraPrice
  86.  
  87. def calcIsValid(self):
  88. self.__reasonsInvalid = []
  89. if self.__height > MAXDIMS:
  90. self.__reasonsInvalid.append("Height over 80cm")
  91. if self.__width > MAXDIMS:
  92. self.__reasonsInvalid.append("Width over 80cm")
  93. if self.__depth > MAXDIMS:
  94. self.__reasonsInvalid.append("Depth over 80cm")
  95. if self.__totalDims > MAXSUMDIMS:
  96. self.__reasonsInvalid.append("Sum of dimensions over 200cm")
  97. if self.__weight > MAXWEIGHT:
  98. self.__reasonsInvalid.append("Weight over 10.0kg")
  99. if self.__weight < MINWEIGHT:
  100. self.__reasonsInvalid.append("Weight under 1.0kg")
  101. if len(self.__reasonsInvalid) != 0:
  102. self.__isValid = False
  103. print("Parcel is invalid:",self.__reasonsInvalid)
  104. else:
  105. self.__isValid = True
  106. print("Parcel is valid.")
  107.  
  108. def loadExample1(self):
  109. self.__weight = 1.0
  110. self.__height = 75.0
  111. self.__width = 30.0
  112. self.__depth = 80.0
  113. self.__price = 0.00
  114. self.__totalDims = 0.0
  115. self.__isValid = True
  116.  
  117. #-----------------------
  118. #CLASS [CONSIGNMENT]:
  119. class Consignment():
  120. def __init__(self):
  121. self.__numTotal = 0
  122. self.__numRejected = 0
  123. self.__numAccepted = 0
  124. self.__totalPrice = 0.00
  125. self.__parcelArray = []
  126.  
  127.  
  128. #GETTERS!
  129. def getNumTotal(self):
  130. return self.__numTotal
  131. def getNumRejected(self):
  132. return self.__numRejected
  133. def getNumAccepted(self):
  134. return self.__numAccepted
  135. def getTotalPrice(self):
  136. return self.__totalPrice
  137. def getParcelArray(self):
  138. return self.__parcelArray
  139.  
  140.  
  141. #SETTERS!
  142. def setNumTotal(self):
  143. self.__numTotal = int(input("Input total number of parcels in consignment:"))
  144. def setNumRejected(self):
  145. self.__numRejected = int(input("Input number of parcels rejected:"))
  146. def setNumAccepted(self):
  147. self.__numAccepted = int(input("Input number of parcels accepted:"))
  148. def setTotalPrice(self):
  149. self.__totalPrice = float(input("Input total price of consignment in pounds and pence:"))
  150.  
  151. # PRINT ALL!
  152. def printAll(self):
  153. print("Total number of parcels:", self.__numTotal)
  154. print("Number of parcels rejected:", self.__numRejected)
  155. print("Number of parcels accepted:", self.__numAccepted)
  156. print("Total Price:", self.__totalPrice)
  157.  
  158. #FUNCTIONS!
  159.  
  160. def addParcel(self, Parcel) -> object:
  161. self.__parcelArray.append(Parcel)
  162. if Parcel.getAccepted() == True:
  163. self.__numAccepted += 1
  164. self.__totalPrice += Parcel.getPrice()
  165. else:
  166. self.__numRejected +=1
  167. print("Added parcel;",self.__totalPrice)
  168.  
  169.  
  170. #MAIN CODE!
  171. Parcel1 = Parcel()
  172. Parcel1.loadExample1()
  173. Parcel1.calcTotalDims()
  174. Parcel1.calcIsValid()
  175. Parcel1.calcPrice()
  176. Parcel1.printAll()
  177.  
  178. NumInConsignment = int(input("\nNumber of parcels in consignment: "))
  179. Consignment1 = Consignment()
  180. for i in range(0,NumInConsignment):
  181. weight = float(input("\nInput weight in kilograms: "))
  182. height = float(input("Input height in centimetres: "))
  183. width = float(input("Input width in centimetres: "))
  184. depth = float(input("Input depth in centimetres: "))
  185.  
  186. inputParcel = Parcel(weight,height,width,depth)
  187. inputParcel.calcTotalDims()
  188. inputParcel.calcIsValid()
  189. inputParcel.calcPrice()
  190. Consignment1.addParcel(inputParcel)
  191.  
  192. Consignment1.printAll()
  193.  
  194.  
  195. print("The end.")
Advertisement
Add Comment
Please, Sign In to add comment