In: Computer Science
Instructions
Modify the Product class from the Practice Exercise 7 by adding a quantity member. Include a getter and setter, using decorators, and modify the appropriate constructor to also accept a quantity parameter.
Then modify the inventory.py file from the practice exercise to include quantity values in the constructor calls with a quantity of 100 for product1 (hammers) and 3000 for product2 (nails). Add print statements to display the quantity values as shown in the Expected Output included below.
Submission
Attach and submit your modified product.py and inventory.py files to this assignment.
Expected Output (new output shown in red, yours does not have to be red).
PRODUCT 1: Name: Stanley 13 Ounce Wood Hammer Price: 11.25 Discount percent: 62% Discount amount: 6.97 Discount price: 4.28 Quantity: 100 PRODUCT 2: Name: National Hardware 3/4" Wire Nails Price: 5.06 Discount percent: 0% Discount amount: 0.00 Discount price: 5.06 Quantity: 3000
This assignment requires a file upload submission (Links to an external site.). After you have reviewed the assignment instructions and rubric, as applicable, complete your submission by selecting the Submit Assignment button next to the assignment title.
product class
class product(object):#main class you can inherit it from object
if you wish else its work fine.
Name='' #declraing all the variable of
product
Price=0
Discount_percent=0
Discount_amount=0
Discount_price=0
Quantity=0
def __init__(self,a,b,c,d): # constructor with
name, price,discount amount and quantity
self.Name=a #asign
respective value
self.Price=b
self.Discount_percent=c
self.Discount_amount=b*(c/100)# asign value after calculating
discount price
self.Discount_price=b-b*(c/100)
self.Quantity=d
def print_product(self):# this function help to
print detail o product
# you can print all
variable of this class by self.variablename but this will help you
lot and give same output with 1 line
print(self.__dict__)#
__dict__ is called magic method in python which print all the
variable of the class
@property # getter method for quantity @property
is called decorator for setter method
def quantity(self):
return
self.Quantity
@quantity.setter # you have to asign decorator
name with name of method asign for getter method and then word
setter
def quantity(self, a):
self.Quantity = a
# creating object of product
product1=product('Stanley 13 Ounce Wood Hammer',11.25,62,100)
product1.print_product()#printing all values of product one
print('quantity is :',product1.Quantity)# calling getter method it
will allow us to access quantity variable without function
#asign new quantity
product1.Quantity=200
print('after setting quantity 200 :',product1.Quantity)
output:--
2nd class
code:--
class inventory(product):
def __init__(self,obj,quantity):# constructor
for inventory.it will accept object and quantity
obj.Quantity=quantity#
asign quantity using inventory object
i1=inventory(product1,100) # creating object for testing
product1.print_product()# asign again 100 quantity to product 1
output:-
NOTE: --
i defind both class on your requirment given but in question i don't know what those class contain earliar so i make it as best.if you have any question let us know.