36.2k views
2 votes
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, and stores the following data in them:

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

User Standy
by
2.9k points

2 Answers

5 votes

Below is an example of a Python class named RetailItem along with a program that creates three RetailItem objects.

python

(this part is missing as it is showing inappropriate word)

# Program to create three RetailItem objects

item1 = RetailItem("Jacket", 12, 59.95)

item2 = RetailItem("Designer Jeans", 40, 34.95)

item3 = RetailItem("Shirt", 20, 24.95)

# Display information about the RetailItems

print("Item #1:", item1)

print("Item #2:", item2)

print("Item #3:", item3)

So, the code above is the RetailItem class that has an __init__ method that initializes the attributes (description, units_in_inventory, and price).

Also, the program then makes three RetailItem objects (item1, item2, and item3) with the specified data and prints out the information about each item.

User Francojohnc
by
3.6k points
3 votes

Answer:

public class Main

{

public static void main(String[] args) {

RetailItem ob1 = new RetailItem("Jacket", 12, 59.95);

RetailItem ob2 = new RetailItem("Designer Jeans", 40, 34.95);

RetailItem ob3 = new RetailItem("Shirt", 20, 24.95);

}

}

class RetailItem {

private String itemDescription;

private int units;

private double price;

public RetailItem(String itemDescription, int units, double price) {

this.itemDescription = itemDescription;

this.units = units;

this.price = price;

}

}

Step-by-step explanation:

Create a class called RetailItem that has three variables itemDescription, units, and price

Initialize a constructor that takes three parameters to set the values

Inside the main, create three objects with given data

User Issac
by
3.2k points