Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, using Python 3 , you are to create a Merchandise data class

ID: 3664386 • Letter: F

Question

For this assignment, using Python 3, you are to create a Merchandise data class and, in a separate file, an executable program named programC.py to test it. Refer to the UML diagram below to create the Merchandise class.

Merchandise

__item
__quantity
__cost

__init__(item,quantity,cost)
set_item(item)
set_quantity(quantity)
set_cost(cost)
get_item()
get_quantity()
get_cost()
get_inventory_value()
__str__()

NOTE: the get_inventory_value() method calculates and prints the value of the merchandise item in currency format.
NOTE: the __str()__ method returns a string showing all 3 attributes and the inventory value (quantity * cost).

In the programC.py main function:

create a Merchandise instance for 10 hammers costing $14.95 each.

create another Merchandise object for 6 necklaces costing $799.99 each.

run the __str__ methods of both objects.

prompt the user for a new quantity for the hammer object, then change this attribute with the setter method.

prompt the user for a new cost for the necklace object, then change this attribute with the setter method.

verify the changes by running the __str__ methods again.

display the inventory value for each object as well.

SAMPLE OUTPUT

hammer, 10 @ $14.95
necklace, 6 @ $799.99
Enter new quantity for hardware 12
Enter new cost for jewelry 659
hammer, 12 @ $14.95
Inventory value: $179.40
necklace, 6 @ $659.00
Inventory value: $3,954.00

Merchandise

__item
__quantity
__cost

__init__(item,quantity,cost)
set_item(item)
set_quantity(quantity)
set_cost(cost)
get_item()
get_quantity()
get_cost()
get_inventory_value()
__str__()

Explanation / Answer

Merchandise

__item

__quantity

__cost

__init

__(item,quantity,cost)

set_item(item)

set_quantity(quantity)

set_cost(cost)

get_item()

get_quantity()

get_cost()

get_inventory_value()

__str__()

class Merchandise:

def __init__(self,item,quantity,cost):

self.__item = item

self.__quantity = quantity

self.__cost = cost def set_item(self,item):

self.__item = item def set_quantity(self,quantity):

self.__quantity = quantity def set_cost(self,cost):

self.__cost = cost def get_item(self):

return self.__item def get_quantity(self):

return self.__quantity def get_cost(self):

return self.__cost def __str__(self):

s = self.__item + ' ' + str(self.__quantity)

s += ' @ ' + str(self.__cost)

return s

## --------SEPARATE PROGRAM TO RUN MERCHANDISE MODULE BELOW----------

## merchandise input program
### import the merchandise module
import merchandise

def main():
### make a new merchandise? instance
store_merchandise = merchandise.Merchandise('hammer',10,14.95)
### display status of merchandise object
print(store_merchandise)

### change Item, Quantity, and Cost
store_merchandise.set_item('necklaces')
store_merchandise.set_quantity(6)
store_merchandise.set_cost(799.99)
### display status of store merchandise object
print(store_merchandise)

item2 = input('Enter new quantity for hardware ') # prompt user for new quantity
### initiate another merchandise
### change Item, Quantity, and Cost
store_merchandise.set_item('hammer')
store_merchandise.set_quantity(item2)
store_merchandise.set_cost(14.95)
### display status of store merchandise object
print(store_merchandise)

necklace2 = input('Enter new cost for necklaces ') # prompt user for new quantity
### initiate another merchandise
### change Item, Quantity, and Cost
store_merchandise.set_item('necklace')
store_merchandise.set_quantity(necklace2)
store_merchandise.set_cost(659.00)
### display status of store merchandise object
print(store_merchandise)


### add the new inventory value total and print the sum

print(store_merchandise + format(store_merch.get_cost(), ',.2f'), sep='')

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote