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

Respuesta :

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;

   }

}

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