The application should store this data in the three objects and display the data
ID: 3769131 • Letter: T
Question
The application should store this data in the three objects and display the data for each employee on the screen. Write a class named Retailltem that holds data about an item in a retail store. The class should have the following properties: Description-The Description property should hold a brief description of the item. UnitsOnHand-The UnitsOnHand property should hold the number of units currently in inventory. The Price property should hold the item's retail price. Write a constructor that accepts arguments for each property. The application should create an array of three Retailltem objects containing the following data: The application should have a loop stens through the array, displaying each element's properties.Explanation / Answer
import java.util.ArrayList; public class RetailItem { private String description; private int unitsOnHand; private double price; public RetailItem(String description, int unitsOnHand, double price) { super(); this.description = description; this.unitsOnHand = unitsOnHand; this.price = price; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getUnitsOnHand() { return unitsOnHand; } public void setUnitsOnHand(int unitsOnHand) { this.unitsOnHand = unitsOnHand; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public static void main(String[] args) { RetailItem r1=new RetailItem("Jacket", 12, 59.95); RetailItem r2=new RetailItem("Jeans", 40, 34.95); RetailItem r3=new RetailItem("Shirt", 20, 24.95); System.out.print(""+" "); System.out.print("Description"+" "); System.out.print("Units On Hand"+" "); System.out.print("Price"+" "); System.out.println(); System.out.println("==========================================================="); RetailItem [] a={r1,r2,r3}; for (int i = 0; i < a.length; i++) { RetailItem r=a[i]; System.out.print(""+" "); System.out.print(r.getDescription()+" "); System.out.print(r.getUnitsOnHand()+" "); System.out.print(r.getPrice()+" "); System.out.println(); } } }
OUTPUT:
Description Units On Hand Price
===========================================================
Jacket 12 59.95 Jeans 40 34.95 Shirt 20 24.95
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.