Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAXDIMS = 80.0
- MAXSUMDIMS = 200.0
- MAXWEIGHT = 10.0
- MINWEIGHT = 1.0
- #F8 TO STEP DOWN A LINE!
- #-----------------------
- #CLASS [PARCEL]:
- class Parcel():
- def __init__(self):
- self.__weight = 0.0
- self.__height = 0.0
- self.__width = 0.0
- self.__depth = 0.0
- self.__price = 0.00
- self.__totalDims = 0.0
- self.__isValid = True
- self.__reasonsInvalid = []
- #GETTERS!
- def getWeight(self):
- return self.__weight
- def getHeight(self):
- return self.__height
- def getWidth(self):
- return self.__width
- def getDepth(self):
- return self.__depth
- def getPrice(self):
- return self.__price
- def getTotalDims(self):
- return self.__totalDims
- def getIsValid(self):
- return self.__isValid
- def getReasonsInvalid(self):
- return self.__reasonsInvalid
- #PRINT ALL!
- def printAll(self):
- print("Weight:",self.__weight)
- print("Height:",self.__height)
- print("Width:",self.__width)
- print("Depth:",self.__depth)
- print("Price:",self.__price)
- print("Total Dimensions:",self.__totalDims)
- print("Is Valid?",self.__isValid)
- print("Reasons Invalid:",self.__reasonsInvalid)
- #SETTERS!
- def setWeight(self):
- self.__weight = float(input("Input weight in kilograms:"))
- def setHeight(self):
- self.__height = float(input("Input height in centimetres:"))
- def setWidth(self):
- self.__width = float(input("Input width in centimetres:"))
- def setDepth(self):
- self.__depth = float(input("Input depth in centimetres:"))
- def setPrice(self):
- self.__price = float(input("Input price in pounds & pence:"))
- def setTotalDims(self):
- self.__totalDims = float(input("Input sum of dimensions in centimetres:"))
- def setIsValid(self):
- self.__isValid = bool(input("Input whether parcel is valid:"))
- def setProperties(self):
- self.__weight = float(input("Input weight in kilograms:"))
- self.__height = float(input("Input height in centimetres:"))
- self.__width = float(input("Input width in centimetres:"))
- self.__depth = float(input("Input depth in centimetres:"))
- #FUNCTIONS!
- def calcTotalDims(self):
- self.__totalDims = self.__height + self.__width + self.__depth
- def calcPrice(self):
- if len(self.__reasonsInvalid) != 0:
- self.__price = 0.00
- else:
- self.__price = 5.00
- if (self.__weight > 5):
- weightDiff = self.__weight - 5
- extraPrice = weightDiff
- self.__price = self.__price + extraPrice
- def calcIsValid(self):
- self.__reasonsInvalid = []
- if self.__height > MAXDIMS:
- self.__reasonsInvalid.append("Height over 80cm")
- if self.__width > MAXDIMS:
- self.__reasonsInvalid.append("Width over 80cm")
- if self.__depth > MAXDIMS:
- self.__reasonsInvalid.append("Depth over 80cm")
- if self.__totalDims > MAXSUMDIMS:
- self.__reasonsInvalid.append("Sum of dimensions over 200cm")
- if self.__weight > MAXWEIGHT:
- self.__reasonsInvalid.append("Weight over 10.0kg")
- if self.__weight < MINWEIGHT:
- self.__reasonsInvalid.append("Weight under 1.0kg")
- if len(self.__reasonsInvalid) != 0:
- self.__isValid = False
- print("Parcel is invalid:",self.__reasonsInvalid)
- else:
- self.__isValid = True
- print("Parcel is valid.")
- def loadExample1(self):
- self.__weight = 1.0
- self.__height = 75.0
- self.__width = 30.0
- self.__depth = 80.0
- self.__price = 0.00
- self.__totalDims = 0.0
- self.__isValid = True
- #-----------------------
- #CLASS [CONSIGNMENT]:
- class Consignment():
- def __init__(self):
- self.__numTotal = 0
- self.__numRejected = 0
- self.__numAccepted = 0
- self.__totalPrice = 0.00
- self.__parcelArray = []
- #GETTERS!
- def getNumTotal(self):
- return self.__numTotal
- def getNumRejected(self):
- return self.__numRejected
- def getNumAccepted(self):
- return self.__numAccepted
- def getTotalPrice(self):
- return self.__totalPrice
- def getParcelArray(self):
- return self.__parcelArray
- #SETTERS!
- def setNumTotal(self):
- self.__numTotal = int(input("Input total number of parcels in consignment:"))
- def setNumRejected(self):
- self.__numRejected = int(input("Input number of parcels rejected:"))
- def setNumAccepted(self):
- self.__numAccepted = int(input("Input number of parcels accepted:"))
- def setTotalPrice(self):
- self.__totalPrice = float(input("Input total price of consignment in pounds and pence:"))
- # PRINT ALL!
- def printAll(self):
- print("Total number of parcels:", self.__numTotal)
- print("Number of parcels rejected:", self.__numRejected)
- print("Number of parcels accepted:", self.__numAccepted)
- print("Total Price:", self.__totalPrice)
- #FUNCTIONS!
- def addParcel(self, Parcel) -> object:
- self.__parcelArray.append(Parcel)
- if Parcel.getAccepted() == True:
- self.__numAccepted += 1
- self.__totalPrice += Parcel.getPrice()
- else:
- self.__numRejected +=1
- print("Added parcel;",self.__totalPrice)
- #MAIN CODE!
- Parcel1 = Parcel()
- Parcel1.loadExample1()
- Parcel1.calcTotalDims()
- Parcel1.calcIsValid()
- Parcel1.calcPrice()
- Parcel1.printAll()
- NumInConsignment = int(input("\nNumber of parcels in consignment: "))
- Consignment1 = Consignment()
- for i in range(0,NumInConsignment):
- weight = float(input("\nInput weight in kilograms: "))
- height = float(input("Input height in centimetres: "))
- width = float(input("Input width in centimetres: "))
- depth = float(input("Input depth in centimetres: "))
- inputParcel = Parcel(weight,height,width,depth)
- inputParcel.calcTotalDims()
- inputParcel.calcIsValid()
- inputParcel.calcPrice()
- Consignment1.addParcel(inputParcel)
- Consignment1.printAll()
- print("The end.")
Advertisement
Add Comment
Please, Sign In to add comment