Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i) Creates a small number of Product instances that may be purchased ii) Accepts simulated 'scanning' of a Product to identify it (including refusal to


i) Creates a small number of Product instances that may be purchased

ii) Accepts simulated 'scanning' of a Product to identify it (including refusal to identify products which do not exist)

iii) Adds a scanned Product to the CheckoutRegister's list of products being purchased

iv) Allows the checkout of multiple products

v) Accepts 'virtual money' to pay for those products (you must pay enough to cover the cost of the items checked out)

vi) Prints a final receipt of the products purchased, along with the total cost, total paid and any change given.


class Product:
  def __init__(self, name, price, barcode, description):
    self.name = name
    self.price = price
    self.barcode = barcode
    self.description = description


class CheckoutRegister:
  def __init__(self):
    self.total_cost = 0
    self.items_scanned = []
    self.amount_paid = 0
 
  def accept_payment(self, some_amount):
    self.amount_paid += some_amount
 
  def scan_item(self, some_product):
    self.items_scanned.append(some_product)
    self.total_cost += some_product.price
 
  def print_receipt(self):
    print("----- Final Receipt -----")
    for item in self.items_scanned:
      print(f"{item.name} ${item.price:.2f}")
    print(" Total amount due: ${:.2f}".format(self.total_cost))
    print("Amount received: ${:.2f}".format(self.amount_paid))
    print("Change given: ${:.2f}".format(self.amount_paid - self.total_cost))
    print(" Thank you for shopping at FedUni!")



from product import Product
from checkoutregister import CheckoutRegister
 
def main():
  print("----- Welcome to FedUni checkout! -----")
  
  # Create instances of Product and CheckoutRegister
  product1 = Product("Milk, 2 Litres", 2.0, "123", "Dairy product")
  product2 = Product("Bread", 3.5, "456", "Bakery product")
 
  checkout = CheckoutRegister()
  
  while True:
    barcode = input("Please enter the barcode of your item: ").strip()
    
    # Check if the barcode exists in your predefined products
    if barcode == product1.barcode:
      checkout.scan_item(product1)
    elif barcode == product2.barcode:
      checkout.scan_item(product2)
    else:
      print("This product does not exist in our inventory.")
    
    another_product = input("Would you like to scan another product? (Y/N) ").strip().lower()
    
    if another_product != 'y':
      break
  
  # Calculate the total cost and prompt for payment
  print(" Payment due: ${:.2f}".format(checkout.total_cost))
  
  while True:
    payment = float(input("Please enter an amount to pay: "))
    if payment < 0:
      print("We don't accept negative money!")
    else:
      break
  
  checkout.accept_payment(payment)
  
  # Display receipt
  checkout.print_receipt()
 
  next_customer = input("(N)ext customer, or (Q)uit? ").strip().lower()
  if next_customer != 'n':
    main()
 
if __name__ == "__main__":
  main()
imageimage

Example Program Output Welcome to FedUni checkout! Please enter the barcode of your item: 123 Milk, 2 Litres - $2.0 Would you like to scan another product? (Y/N) Y Please enter the barcode of your item: 456 Bread - $3.5 Would you like to scan another product? (Y/N) Y Please enter the barcode of your item: 999 This product does not exist in our inventory. Would you like to scan another product? (Y/N) n Payment due: $5.5. Please enter an amount to pay: 5 Payment due: $0.5. Please enter an amount to pay: -3 We don't accept negative money!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Management Accounting

Authors: Leslie G. Eldenburg, Albie Brooks, Judy Oliver, Gillian Vesty, Rodney Dormer, Vijaya Murthy, Nick Pawsey

4th Edition

0730369382, 978-0730369387

More Books

Students also viewed these Programming questions

Question

How are externalities reduced within a firm?

Answered: 1 week ago

Question

preparing for and completing job interviews and considering offers.

Answered: 1 week ago

Question

4.8 Describe ways of understanding and treating PTSD.

Answered: 1 week ago