Write a class named Product that holds data about an item in

Write a class named Product that holds data about an item in a retail store. The class should store the following data in attributes: product id, item description, units in inventory, and price. Write the_init_method to require all four attributes. Also write a_str_method for debugging output. Once you have written the class, write a main() function that creates three Product objects and stores the following data in them. Use the_str_method to confirm the data is stored properly. Create an Inventory module by moving the Product Class definition to another file called inventory.py. Add three_doc_strings: one that describes the inventory module (include your name and the date here), one that describes the Product class, and one that describes the Product class _init_method. Rename your main() function to test inventory.py Add an import at the top of the file to read the Product class definition. Add calls to test the three_doc_strings. Test the program to be sure it still works.

Solution

Part 1:
class RetailItem:

    # __int__ method initializes the attributes.
    def __init__(self, description, units, price):
        self.__item_description = description
        self.__units_in_inventory = units
        self.__price = price

    # The set_item_description method gets the item type.
    def set_item_description(self, description):
        self.__item_description = description

    # The set_units_in_inventory method gets number of items available.
    def set_units_in_inventory(self, units):
        self.__units_in_inventory = units

    # The set_price method gets the cost of item.
    def set_price(self, price):
        self.__price = price

    # The get_item_description method returns the item type.
    def get_item_description(self):
        return self.__item_description

    # The get_units_in_inventory returns the number of items available.
    def get_units_in_inventory(self):
        return self.__units_in_inventory

    # The get_price method returns the cost of item.
    def get_price(self):
        return self.__price

import sys

# This defines the main function.
def main():
    # Get a list of RetailItem objects.
    inventory = make_list()

    # Display the data in the list.
    print(\'Here is the data you entered:\')
    display_list(inventory)

    # The make_list will get data for three items. It will
    #return a list of available items.

def make_list():
    # Create an empty list.
    item_list = []
    item = \'Jacket\'
    units = 12
    price = 59.95
    item = \'Designer Jeans\'
    units = 40
    price = 34.95
    item = \'Shirt\'
    units = 20
    price = 24.95
  
    print(\'Enter data for three items.\')
    for count in range(1, 4):
        # Get item data.
        print(\'Item number \' + str(count) + \':\')
        item = input(\'Enter description of item: \')
        units = float(input(\'Enter number of units in inventory: \'))
        price = float(input(\'Enter price per item: \'))
        print()

        # Creat new RetailItem and assign items variable.
        items = RetailItem(item, units, price)
        # Add items to list.
        item_list.append(items)

        return item_list

#Display the items information.
def display_list(item_list):
    for item in item_list:
        print(item.get_item_description())
        print(item.get_units_in_inventory())
        print(item.get_price())
        print()

# Call the main function.
main()


Part 2:


class RetailItem:

    # __int__ method initializes the attributes.
    def __init__(self, description, units, price):
        self.__item_description = description
        self.__units_in_inventory = units
        self.__price = price

    # The set_item_description method gets the item type.
    def set_item_description(self, description):
        self.__item_description = description

    # The set_units_in_inventory method gets number of items available.
    def set_units_in_inventory(self, units):
        self.__units_in_inventory = units

    # The set_price method gets the cost of item.
    def set_price(self, price):
        self.__price = price

    # The get_item_description method returns the item type.
    def get_item_description(self):
        return self.__item_description

    # The get_units_in_inventory returns the number of items available.
    def get_units_in_inventory(self):
        return self.__units_in_inventory

    # The get_price method returns the cost of item.
    def get_price(self):
        return self.__price


# This program will test the RetailItem class and return information
# using the mutator method.

import sys

# This defines the main function.
def main():
    # Get a list of RetailItem objects.
    inventory = make_list()

    # Display the data in the list.
    print(\'Here is the data you entered:\')
    display_list(inventory)

    # The make_list will get data for three items. It will
    #return a list of available items.

def make_list():
    # Create an empty list.
    item_list = []

    # Add three item to the list.
    print(\'Enter data for three items.\')
    for count in range(1, 4):
        # Get item data.
        print(\'Item number \' + str(count) + \':\')
        item = input(\'Enter description of item: \')
        units = float(input(\'Enter number of units in inventory: \'))
        price = float(input(\'Enter price per item: \'))
        print()

        # Creat new RetailItem and assign items variable.
        items = RetailItem(item, units, price)
        # Add items to list.
        item_list.append(items)

        return item_list

#Display the items information.
def display_list(item_list):
    for item in item_list:
        print(item.get_item_description())
        print(item.get_units_in_inventory())
        print(item.get_price())
        print()

# Call the main function.
main()

 Write a class named Product that holds data about an item in a retail store. The class should store the following data in attributes: product id, item descript
 Write a class named Product that holds data about an item in a retail store. The class should store the following data in attributes: product id, item descript
 Write a class named Product that holds data about an item in a retail store. The class should store the following data in attributes: product id, item descript

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site