ITECH1400 Foundations of Programming: Supermarket Self-Checkout Design

Verified

Added on  2024/05/31

|7
|862
|92
Homework Assignment
AI Summary
This assignment solution for ITECH1400 Foundations of Programming details the design and implementation of a supermarket self-service checkout system. The solution includes class diagrams for 'Product' and 'CheckoutRegister', an activity flowchart illustrating the checkout process, and software implementation snippets with explanations. Key aspects covered are product properties, barcode handling, payment acceptance, receipt printing, and a bagging algorithm that manages item weights. The code explanation focuses on functions for accepting payments and bagging products efficiently, ensuring that the bag weight does not exceed the maximum limit. The assignment also demonstrates how to handle scenarios where items cannot be bagged due to weight restrictions, placing them into a non-bagged items list. Desklib offers more solved assignments and study resources for students.
Document Page
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
ITECH1400 - Assignment – Supermarket Self-Service Checkout
Assignment Part 1 Details – Class Design
Product Properties (All)
Barcode Name Price Weight
001 handset 32.0 1.4
002 hardware 34.01 2.5
003 drive 231.90 1.4
004 Mobile 36.0 0.5
005 fan 74.50 2.0
006 PC 59.0 1.8
007 notebook 12.50 0.5
008 Compact disk 17.90 1.10
009 ROM 523.50 2.90
Product Properties (Key)
Barcode Name Price Weight
Product Class Diagram
Product
+ pro_barcode:var=var
+ pro_name:var=var
+ pro_price:var=var
+ pro_weight:var=var
+ product_item_list = []
+_init_()
CRICOS Provider No. 00103D Page 1 of 7
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
CheckoutRegister Class Diagram
CheckoutRegister
+ remainingPayment_amount:var = 0
+ some_money:var = 0
+ MAX_BAG_WEIGHT = 5.0
+__init__(self)
+ can_item(self,product_barcode)
+ accept_payment(self,some_money)
+ print_receipt(self)
+ bag_products(self,product_list)
CRICOS Provider No. 00103D Page 2 of 7
Document Page
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
Assignment Part 2 – Activity Flowchart
CRICOS Provider No. 00103D Page 3 of 7
Document Page
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
Assignment Part 3 – Software Implementation
Figure 1 Output
CRICOS Provider No. 00103D Page 4 of 7
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
Figure 2 Output
CRICOS Provider No. 00103D Page 5 of 7
Document Page
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
Assignment Part 4 – Code Explanation and Use
1. # make a function for accept_payment from customers for their shopping of items
defget_float(prompt):
2. # define variable with float value 0.0
value= float(0.0)
3. # run while loop till condition is true for accept payment
whileTrue:
a. try:
i. # input for amount due after accepting payment and give back remained amount to customer
value= float(input(prompt))
ii. # check condition for negative values of amount using if loop
if value < 0.0:
print("We don't accept negative money!")
continue
iii. # if this condition matches then jump from this loop to next step
break
b. # exception handling for value error
exceptValueError:
print('Please enter a valid floating point value.')
4. # pass the total amount where this function called for shopped product by customers
return value
# make a function for bag_products to append the items from the shopped item list to bag_list until weight of bag is less than
and equal to the MAX_BAG_WEIGHT
# extra items move to non_bagged_list
5. defbag_products(product_list):
6. # make a list of bag_list, non_bagged_items and set max weight to 0.5
bag_list=[]
non_bagged_items=[]
MAX_BAG_WEIGHT = 5.0
6. # run for loop for products in product list
for product inproduct_list:
7. # check for condition using if-else for pro_weight > MAX_BAG_WEIGHT and do removing or appending of items
from product_list and non_bagged_items
ifproduct.weight> MAX_BAG_WEIGHT:
product_list.remove(product)
non_bagged_items.append(product)
8. # make a list for current_bag_contents and 0.0 value for current_bag_weight
current_bag_contents=[]
CRICOS Provider No. 00103D Page 6 of 7
Document Page
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
current_bag_weight= 0.0
9. # run while loop for given condition
whilelen(product_list)> 0:
10. # swapping of values and remove temporary product after swap from product_list
temp_product=product_list[0]
product_list.remove(temp_product)
11. # check for given condition using if-else conditions
ifcurrent_bag_weight+temp_product.weight< MAX_BAG_WEIGHT:
12. # add temporary_product into current_bag_contents
current_bag_contents.append(temp_product)
current_bag_weight+=temp_product.weight
13. # check length of product list using if condition which is equal to 0 add append to current_bag_contents
if(len(product_list)== 0):
bag_list.append(current_bag_contents)
14. # otherwise if product list is not empty then append to current bag contents
else:
bag_list.append(current_bag_contents)
15. # enumerate(bag_list ) adds a counter to an iterate
for index, bag in enumerate(bag_list):
output= 'Bag ' +str(index + 1)+ ' contains: '
16. # show products which are in bag
for product in bag:
output+= product.name + '\t'
print(output, '\n')
17. # check condition using if loop for non_bagged_items length should not be greater than 0
if(len(non_bagged_items)> 0):
output= 'Non-bagged items: '
18. # for loop to print non_bagged_items
for item innon_bagged_items:
output+= item + '\t'
print(output,'\n')
CRICOS Provider No. 00103D Page 7 of 7
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]