SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Classes And Object Oriented Programming
Exercise:
Programming Exercises
Question:5 | ISBN:9780132576376 | Edition: 2

Question

RetailItem Class
Write a class named RetailItem that holds data about an item in a retail store. The class should store the following data in attributes: item description, units in inventory, and price. Once you have written the class, write a program that creates three RetailItem objects. 

                                   Description                Units in Inventory              Price
Item #1                          Jacket                             12                                 59.95
Item #2                          Designer Jeans               40                                34.95
Item #3                           Shirt                                20                                24.95

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

RetailItem Class Program Code:

#Createa a class name, RetailItem
class RetailItem:
    def __init__(self, description, units_in_inventory, price):
        self.description = description
        self.units_in_inventory = units_in_inventory
        self.price = price

# Create three RetailItem objects with the provided data
item1 = RetailItem("Jacket", 12, 59.95)
item2 = RetailItem("Designer Jeans", 40, 34.95)
item3 = RetailItem("Shirt", 20, 24.95)

# Display the data for each RetailItem object
print("Item #1:")
print("Description:", item1.description)
print("Units in Inventory:", item1.units_in_inventory)
print("Price:", item1.price)

print("\nItem #2:")
print("Description:", item2.description)
print("Units in Inventory:", item2.units_in_inventory)
print("Price:", item2.price)

print("\nItem #3:")
print("Description:", item3.description)
print("Units in Inventory:", item3.units_in_inventory)
print("Price:", item3.price)

Executed Output:

Item #1:
Description: Jacket
Units in Inventory: 12
Price: 59.95

Item #2:
Description: Designer Jeans
Units in Inventory: 40
Price: 34.95

Item #3:
Description: Shirt
Units in Inventory: 20
Price: 24.95

 

0 0

Discussions

Post the discussion to improve the above solution.