Question

**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...

**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of the data member).

Here are the method descriptions for the three classes:

**Product:**

A product object represents a product with an ID code, title, description, price, and quantity available.

* init method - Takes as parameters five values with which to initialize the Product: it's ID, title, description, price, and quantity_available. You can assume unique IDs will be used.

* get methods for each of the data members, named get_product_id, get_title, get_description, get_price, and get_quantity_available

* decrease_quantity - Decreases the quantity available by one

**Customer:**

A Customer object represents a customer with a name and account ID. Customers must be members of the Store to make a purchase. Premium members get free shipping.

* init method - Takes as parameters three values with which to initialize the Customer: their name, ID, and whether the customer is a premium_member (that last one is a Boolean value).

* A customer's cart is a collection of Product ID codes - you can choose what type of collection (e.g. list, dictionary, etc.). Since the cart is private, you'll also need to create a get method for it

* get methods named get_name and get_customer_id

* is_premium_member - Returns whether the customer is a premium member (True or False)

* add_product_to_cart - Takes a product ID code and adds it to the Customer's cart

* empty_cart - Empties the Customer's cart

**Store:**

A Store object represents a store, which has some number of products in its inventory and some number of customers as members.

* A Store's inventory is a collection of Products that are part of the Store - you can choose what type of collection (e.g. list, dictionary, etc.)

* A Store's membership is a collection of Customers that are members of the Store - you can choose what type of collection (e.g. list, dictionary, etc.)

* init method - Does whatever initialization is needed for your Store * add_product - Takes a Product object and adds it to the inventory * add_member - Takes a Customer object and adds it to the membership

* get_product_from_id - Takes a Product ID and returns the Product with the matching ID. If no matching ID is found in the inventory, it returns the special value None

* get_member_from_id - Takes a Customer ID and returns the Customer with the matching ID. If no matching ID is found in the membership, it returns the special value None * product_search - Takes a search string and returns a sorted (in lexicographic order) list of ID codes for every product in the inventory whose title or description contains the search string. The search should be case-insensitive, i.e. a search for "wood" should match Products that have "Wood" in their title or description, and a search for "Wood" should match Products that have "wood" in their title or description (such as "woodchuck"). The list of ID codes should not contain duplicates. You may assume that the search string will consist of a single word. If the search string is not found, return an empty list.

* add_product_to_member_cart - Takes a Product ID and a Customer ID (in that order). If the product isn't found in the inventory, return "product ID not found". If the product was found, but the member isn't found in the membership, return "member ID not found". If both are found and the product is still available, call the member's addProductToCart method to add the product and then return "product added to cart". If the product was not still available, return "product out of stock". This function does not need to check how many of that product are available - just that there is at least one. It should not change how many are available - that happens during checkout. The same product can be added multiple times if the customer wants more than one of something.

* check_out_member - Takes a Customer ID. If the ID doesn't match a member of the Store, raise an **InvalidCheckoutError** (you'll need to define this exception class). Otherwise return the charge for the member's cart. This will be the total cost of all the items in the cart, not including any items that are not in the inventory or are out of stock, plus the shipping cost. If a product is not out of stock, you should add its cost to the total and decrease the available quantity of that product by 1. Note that it is possible for an item to go out of stock during checkout. For example, if the customer has two of the same product in their cart, but the store only has one of that product left, the customer will be able to buy the one that's available, but won't be able to buy a second one, because it's now out of stock. For premium members, the shipping cost is $0. For normal members, the shipping cost is 7% of the total cost of the items in the cart. When the charge for the member's cart has been tabulated, the member's cart should be emptied, and the charge amount returned. Don't round any results.

**[10 pts]** **You must include a main function** that runs if the file is run as a script, but not if the file is imported. The main function should try to check out a member. If an InvalidCheckoutError is raised, it should be caught with a try/except that prints an explanatory message for the user (otherwise the checkout should proceed normally).

**[20 pts]** In addition to your file containing the code for the above classes, **you must also submit a file named StoreTester.py** that contains unit tests for your Store.py file. It must have at least five unit tests and use at least three different assert functions. This part (like the rest) must be your own work - do not copy someone else's work.

Here's a very simple example of how your classes could be used:

```

p1 = Product("889", "Rodent of unusual size", "when a rodent of the usual size just won't do", 33.45, 8)

c1 = Customer("Yinsheng", "QWF", False)

myStore = Store()

myStore.add_product(p1)

myStore.add_member(c1)

myStore.add_product_to_member_cart("889", "QWF")

result = myStore.check_out_member("QWF")

```

Your files must be named: **Store.py** and **StoreTester.py**

Homework Answers

Answer #1

Python code to copy:-

Store.py

import re

class Product:

def __init__(self,id_code,title,description,price,quantity):

self.id_code = id_code
self.title = title
self.description = description
self.price = price
self.quantity = quantity
#Getters and Setters

def get_id_code(self):
return self.id_code

def get_title(self):
return self.title

def get_description(self):
return self.description

def get_price(self):
return self.price

def get_quantity(self):
return self.quantity

def decrease_quantity(self):
self.quantity = self.quantity - 1
return self.quantity

class Customer:

def __init__(self,name,account_id,premiumMember):

self.name = name
self.account_id = account_id
self.premiumMember = premiumMember
self.cart = []

#Getters and Setters

def get_cart(self):
return self.cart
  
def get_name(self):

return self.name

def get_account_ID(self):

return self.account_id

def is_premium_member(self):

return self.premiumMember

def add_product_to_cart(self,id_code):

self.cart.append(id_code)

def empty_cart(self):

self.cart = []

  
class Store:

def __init__(self):

self.inventory = []

self.members = []

def add_product(self,product):

self.inventory.append(product)

def add_member(self,customer):

self.members.append(customer)

def get_product_from_ID(self,id_code):
#Iterate through inventory
for p in self.inventory:
  
if id_code == p.get_id_code():
  
return p
  
return None
  
def get_member_from_ID(self,account_id):
#Iterate through members
for c in self.members:
  
if c.get_account_ID() == account_id:

return c

return None

def add_product_to_member_cart(self,pID,mID):


#Check product
p = self.get_product_from_ID(pID)
#Check Customer
m = self.get_member_from_ID(mID)
  
if p is None:
  
return "product ID not found"

elif m is None:
  
return "member ID not found"

else:
quan = p.get_quantity()
#if available add to cart
if quan > 0:
m.add_product_to_cart(p.get_id_code())
return "product added to cart"
else:
return "product out of stock"

def check_out_member(self,mID):   
#This is the sum total of prices of products
sum_total = 0.00
#This is the total plus shipping cost
grand_total = 0.00
#This is the shipping charges
ship = 0.0

c = self.get_member_from_ID(mID)

if c is None:
raise InvalidCheckoutError()
else:
#Print cart
if len(c.get_cart()) == 0:
print("No items in cart");
#Generate cart total
for i in c.get_cart():
  
p = self.get_product_from_ID(i)

if p.get_quantity() <= 0:
print("Sorry,product " + p.get_id_code() + "," + p.getTitle())
else:
sum_total = sum_total + p.get_price()
p.decrease_quantity()
#Check premium
if c.is_premium_member() is True:
#No shipping charges
  
grand_total = sum_total
else:
#Shipping charges included
ship = 0.07*sum_total
grand_total = sum_total + ship

print("Subtotal: $" +str(sum_total))
print("Shipping Cost: $" + str(ship))
print("Total: $" + str(grand_total))
  
c.empty_cart()
return grand_total

def productSearch(self,txt):
found = False

id_codes = []

#Extracting the first character
f = txt[:1]
#Extracting the rest of the characters
r = txt[1:]

#Creating a pattern object with first character search insensitive and the rest are case-sensitive
t = re.compile("(?i)" + f + r)
for p in self.inventory:
  
if re.search(t,p.get_title()) or re.search(t,p.get_description()):
id_codes.append(p.get_id_code())

#Sorting the list in ascending order
id_codes.sort()

#Returning sorted list
return id_codes
  
#The custom error class defined
class InvalidCheckoutError(BaseException):

pass


if __name__ == '__main__':

store = Store()

#dummy product

p1 = Product("889", "Rodent of unusual size", "when a rodent of the usual size just won't do", 55, 3)
p2 = Product("31", "milk", "umm yummy", 23, 1)

#dummy customer
c = Customer("Yinsheng", "QWF", False)

store.add_product(p1)
store.add_product(p2)
store.add_member(c)
  
store.add_product_to_member_cart(p1.get_id_code(),c.get_account_ID())
store.add_product_to_member_cart(p2.get_id_code(),c.get_account_ID())

print(store.productSearch("Milk"))

try:
store.check_out_member(c.get_account_ID())
except InvalidCheckoutError:
print("Customer not found in member list")


  
  

StoreTester.py

import unittest
import Store

class TestStore(unittest.TestCase):

def test_Store(self):

#Creating a product object
p = Store.Product(1,"Laptop","Portable Computer",200.00,2)
  
self.assertEqual(p.get_title(),"Laptop")
self.assertEqual(p.get_description(),"Portable Computer")
self.assertEqual(p.get_price(),200.00)

#Two different assert statements
self.assertNotEqual(p.get_quantity(),3)
self.assertIsNotNone(p)

unittest.main()

ScreenShot:-

Store.py

StoreTester.py

Output:-

Store.py

StoreTester.py

Thank You....!!!!
For any query, please comment.
If you are satisfied by the above answer, then please thumbs up or upvote the answer.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If...
Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If you can't implement all of the features of Project described in this document, implement what you can. Start by implementing the StockItem class, and its derived classes. Then add in the InventoryManager class later. In each case, the test files must be in separate classes. UML Diagram: Use Violet or other drawing software to draw the UML diagrams of each class that you use...
Acme Super Store is having a contest to give away shopping sprees to lucky families. If...
Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins a shopping spree each person in the family can take any items in the store that he or she can carry out, however each person can only take one of each type of item. For example, one family member can take one television, one watch and one toaster, while another family member can take one television, one camera and one pair...
Hello, can you teach me how to draw a Use Case diagram for this given scenario?...
Hello, can you teach me how to draw a Use Case diagram for this given scenario? I also need to include all the extends and includes relationships. Case Description Acme Drug Stores (ADS) which consists of a chain of retail stores across Canada wants to be able to provide a new online customer service system. Each store has an identifying store no, address, phone, and email. The company dispenses a wide range of pharmaceutical (drug) products. Each product has a...
You can complete this assignment individually or as a group of two people. In this assignment...
You can complete this assignment individually or as a group of two people. In this assignment you will create a ​​Sorted Singly-Linked List​ that performs basic list operations using C++. This linked list should not allow duplicate elements. Elements of the list should be of type ‘ItemType’. ‘ItemType’ class should have a private integer variable with the name ‘value’. Elements in the linked list should be sorted in the ascending order according to this ‘value’ variable. You should create a...
QUESTION 1 You have received an invite to be the accountant for a client who already...
QUESTION 1 You have received an invite to be the accountant for a client who already has a QuickBooks Online account. Where will you find the Accept Invite button? Within the client dashboard This will be assigned to a team member On your QuickBooks Online Accountant Dashboard Within the invitation email 5 points    QUESTION 2 There are four types of items in the Products and Services list. If your client wanted to sell a combination of products and services,...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
Wal-Mart Online Wal-Mart is one of the largest companies in America. It is definitely the largest...
Wal-Mart Online Wal-Mart is one of the largest companies in America. It is definitely the largest retailer, both in terms of the number of stores (8,970 worldwide in 2011) and the level of sales ($419 billion from the 2011 Annual Report). By pushing suppliers to continually reduce costs, Wal-Mart is known for pursuing low prices and the stores often attract customers solely in-terested in lower prices. With Wal-Mart’s expansion into groceries, the company has be-come the largest retail grocer in...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT