Design and model two classes: Product and CheckoutRegister
Insert your list/table of possible product properties here…
Product Properties (All)
price |
mfgDate |
expiryDate |
BatchNo |
weight |
barcode |
name |
ingredients |
address |
|
mfgUnit |
fax |
Insert your list/table of key product properties here…
Product Properties (Key)
name |
price |
weight |
barcode |
Complete the class diagram of your final Product class here
Update the below code to insert comments describing what the code is doing – for each line starting with a hash symbol (#) you should write your code comments after the hash. You may add a second line of comments if you require more space.
# Function to: read a float value from the user
#and return this float value to the calling function
def get_float(prompt):
# take a variable value of type float and initialize it
# with value 0.0
value = float(0.0)
# infinite loop to carry on till a valid float value is entered by the user
while True:
try:
# take an input from the user
# typecast that entered value into a float value
value = float(input(prompt))
# if value was successfully parsed
# but the entered value is less then 0,
# print an error message and continue to loop
if value < 0.0:
print(“We don’t accept negative money!”)
continue
# value entered by the user is a valid value.
# break the loop
break
# value entered by the user was not a valid float value
# so an exception is thrown
except ValueError:
print(‘Please enter a valid floating point value.’)
# return the parsed float value to the calling function.
return value
# Function to: bag the products that are purchased by the user
def bag_products(product_list):
# list of the bags as the items purchased by the user
# may take more then one bags
bag_list = []
non_bagged_items = []
MAX_BAG_WEIGHT = 5.0
# for each product in the list of goods purchased by the user
# perform this loop
for product in product_list
# weight of current product is more then
# the maximum weight that this bag can hold,
# so add this product to the list of items which will not be bagged
if product.weight > MAX_BAG_WEIGHT:
product_list.remove(product)
non_bagged_items.append(product)
# take an empty new bag to place the goods of the user
current_bag_contents = []
current_bag_weight = 0.0
# loop until the basket of goods purchased by the user still has items
while len(product_list) > 0:
# take the first products out of the basket
# and name it as temp_product
temp_product = product_list[0]
product_list.remove(temp_product)
# check whether the current product can be added
# to the current bag or not
# for this, check that adding this product will not overfloew the bag
if current_bag_weight + temp_product.weight < MAX_BAG_WEIGHT:
# if this product can be added, add it to the current bag
current_bag_contents.append(temp_product)
current_bag_weight += temp_product.weight
# if all the items of the basket are packed
# add this bag to list of bags for the user
if (len(product_list) == 0):
bag_list.append(current_bag_contents)
# the current product can not be added to this bag,
# so add the current bag to the list of bags for the user
else:
bag_list.append(current_bag_contents)
# take a fresh bag and set its weight to 0
current_bag_contents = []
current_bag_weight = 0.0
# loop through list of all bags to print their contents
# by bag number
for index, bag in enumerate(bag_list):
output = ‘Bag ‘ + str(index + 1) + ‘ contains: ‘
# for each product in the current bag, add its name
# to the list of user items in this bag
for product in bag:
output += product.name + ‘t’
print(output, ‘n’)
# there are also some items that were not packed
if (len(non_bagged_items) > 0):
output = ‘Non-bagged items: ‘
# traverse these items to print their contents
for item in non_bagged_items:
output += item + ‘t’
print(output,’n’)