Answer To: ITECH1400 – Foundations of Programming – SEM2/18 School of Science, Engineering and Information...
Meenakshi answered on Aug 26 2020
assignment3python/CheckoutRegister.py
class CheckoutRegister():
def __init__(self,checkout_date,checkout_items):
self.checkout_date = checkout_date
self.checkout_items = checkout_items
def add_item_to_cart(self,p):
self.checkout_items.append(p)
def display_checkout_items(self):
print("Checkout Items")
print(self.checkout_items)
def calculate_payment_due(self):
cart_items = self.checkout_items
cart_totals = 0
for index, product in enumerate(self.checkout_items):
cart_totals += product['price']
self.due = cart_totals
return cart_totals
def pay_money(self,total):
amount_to_pay = total
print("\nPayment due: $"+str(amount_to_pay))
#self.accept_payment(amount_to_pay)
#amount_to_pay = input("Please enter an amount to pay: ")
change = self.accept_payment(amount_to_pay)
return change
def accept_payment(self, amount_to_pay):
#print("accept payment")
paid = float(0.0)
customer_pay = float(0.0)
due = float(0.0)
total = amount_to_pay
due = True
while due == True:
try:
paid = float(input("\nPlease enter an amount to pay: "))
if(paid < 0.0):
print("We don't accept negative money!\n")
continue
else:
customer_pay += paid
self.customer_pay = customer_pay
if(paid < total):
due = total - paid
total = due
print("Payment due: $"+str(due))
due = True
continue
else:
change = paid - total
self.change = change
#print("Change: ",change)
return change
break
break
#due = False
#self.print_receipt(change)
except ValueError:
print('Please enter a valid floating point value.')
return change
def print_receipt(self,change):
print("\n----- Final Receipt -----\n")
for index, item in enumerate(self.checkout_items):
print(item['name'],' $'+str(item['price']))
print("\n")
print("Total amount due:",' $'+str(self.due))
print("Amount Received",' $'+str(self.customer_pay))
print("Change Given",' $'+str(self.change),'\n')
assignment3python/main.py
from product import Product
from checkoutregister import CheckoutRegister
from time import gmtime, strftime
#import sys
import os
import sys
current_date_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
wishlist = []
def scan_product():
barcode = input("\nPlease enter the barcode of your item: ")
p1 = Product("","",barcode)
search_product = p1.check_product_on_inventory()
if(search_product == False):
print("This product does not exist in our inventory.\n")
scan_another()
else:
wishlist.append(search_product)
scan_another()
def scan_another():
scan_another = input("Would you like to scan another product? (Y/N)")
if(scan_another == 'y' or scan_another == 'Y'):
scan_product()
def main():
scan_product()
c1 = CheckoutRegister(current_date_time,wishlist)
total_payment = c1.calculate_payment_due()
change = c1.pay_money(total_payment)
#print("Change:",change)
c1.print_receipt(change)
print("\nThank you for shopping at neelam!")
next = input("(N)ext customer, or (Q)uit? ")
if(next == "n" or next == "N"):
wishlist[:] = []
main()
else:
#sys.exit(0)
exit()
print("\n--------Welcome neelam checkout!--------\n")
main()
assignment3python/product.py
class Product():
product_list = [
{
'name': 'cofee litres',
'price': 101,
'bar_code': '1'
},
{
'name': 'chips namken',
'price': 11,
'bar_code': '2'
},
{
'name': 'butter and butter',
'price':212,
'bar_code':'3'
}
]
def __init__(self,name,price,bar_code):
self.name = name
self.price = price
self.bar_code = bar_code
def display_product(self):
print(self)
#print 'Human readable: ', str(self)
#print repr(self)
def display_product_list(self):
print("Our inventory")
def check_product_on_inventory(self):
found = False
for index, product in enumerate(self.product_list):
#print(product)
if self.bar_code == product['bar_code']:
product_found = {'name': product['name'],'price': product['price'],'bar_code': product['bar_code']}
found = True
print(product['name']," - $"+str(product['price']),'\n' )
if found == True :
return product_found
else:
return False
def set_bar_code(self,bar_code):
self.bar_code = bar_code
def set_price(self,price):
self.price = price
assignment3python/selfservicecheckout1.docx
SUPER-MARKET SELF-SERVICE CHECKOUT
This project is related to super market self service checkout system assignment and this project require two basic file product that is related to product information like price, name these product require unique id that is bar code and another requirement is checkout register where product delivery information shown . First assignment is we prepare a class diagram for product and checkout register where product class having the information about the product and checkout register is for product check list .Second assignment design an activity diagram for checklist register in this project. Third assignment is implements the concept in python code and fourth assignment is given code explanation...
Assignment Part 1 – Class Diagram
Class DIAGRAM
(
Product
Name: character
barcode: number
Price : number
Quantity:number
Product()
Get()
Set()
Checkinventory()
Displayproduct()
Display rpdut
) (
Checkoutregister
Barcode:number
date:date
checkoutitem
Additemtocard(product)
paymoney()
accept
payment(amtopay)
checkinventory()
displaychekout()
)
Assignment Part 2 – activity diagram
CHECK OUT REGISTER ACTIVITY DIAGRAM
Assignment Part 4 – Code Explanation and Use
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: __________________define the function_________
defget_float(prompt):
# ______set the variable value 0.0______________________________
value =float(0.0)
# _repeat until condition false___________________________________
whileTrue:
try:
# ______input the value in float______________________________
value = float(input(prompt))
# _checking the value if less than zero then message___________________________________
if value <0.0:
print("We don't accept negative money!")
continue
# _________break the value___________________________
break
# _________exception raise___________________________
exceptValueError:
print('Please enter a valid floating point value.')
# ___return the value_________________________________
return value
# Function to: ___store in list_______________________
defbag_products(product_list):
# ___________array define for list of product__and non bag item___,set max veight =5__________________
bag_list=[]
non_bagged_items=[]
MAX_BAG_WEIGHT =5.0
# loop for product lisr____________________________________
for product inproduct_list:
# ___check the weight weight greater than max then add into non bag list_________________________________
ifproduct.weight> MAX_BAG_WEIGHT:
product_list.remove(product)
non_bagged_items.append(product)
# __array for bag contents and weight__________________________________
current_bag_contents=[]
current_bag_weight=0.0
# _______________loop work until list not 0_____________________
whilelen(product_list)>0:
# __assign the temp from product lust and remove from product lost_________________________________
temp_product=product_list[0]
product_list.remove(temp_product)
# ______check the current bag and product weight less than max____________________________
ifcurrent_bag_weight+temp_product.weight< MAX_BAG_WEIGHT:
# _______value is add in current bag from temp and add weight____________________________
current_bag_contents.append(temp_product)
current_bag_weight+=temp_product.weight
# ________check the list =0 then append the product contents____________________________
if(len(product_list)==0):
bag_list.append(current_bag_contents)
# _______otherwise add bag list in current bag contents into bag list_____________________________
else:
bag_list.append(current_bag_contents)
# _array for bag content set current bag weight__________________________________
current_bag_contents=[]
current_bag_weight=0.0
# __loop for bag list__________________________________
for index, bag in enumerate(bag_list):
output ='Bag '+str(index +1)+' contains: '
# _repeat until display the value___________________________________
for product in bag:
output += product.name +'\t'
print(output,'\n')
# ___check the length_________________________________
if(len(non_bagged_items)>0):
output ='Non-bagged items: '
# _________________loop for non bag item display__________________
for item innon_bagged_items:
output += item +'\t'
print(output,'\n')