4. R e t a i l l t em Class Write a class named Retailltein that holds data abou
ID: 671498 • Letter: 4
Question
4. R e t a i l l t em Class
Write a class named Retailltein that holds data about an item in a retail Mine. The ilass
should have the following fields:
• description. The description field references a String object that holds a brief
description of the item.
• unitsOnHand. The unitsOnHand field is an i n t variable that holds the number of units
currently in inventory.
• price. The price field is a double that holds the item's retail price.
Write a constructor that accepts arguments for each field, appropriate mutator method',
that store values in these fields, and accessor methods that return the values in these fields.
Once you have written the class, write a separate program that creates three Retailltem
objects and stores the following data in them:
Description Units on Hand Price
Item «I
Item n
Item 13
Jacket
Designer Jeans
Shirt
12
40
20
59.95
34.95
24.95
Explanation / Answer
public class testRetail
{
public static void main(String[] args){
Retailltein item1=new Retailltein("Jacket", 12, 59.95);
Retailltein item2=new Retailltein("Designer Jeans",40,34.95);
Retailltein item3=new Retailltein("Shirt",20,24.95);
}
}
public class Retailltein {
String description;
int unitsOnHand;
double price;
public Retailltein(String des,int u,double price){
this.description=des;
this.unitsOnHand=u;
this.price=price;
}
public String getDescription(){
return description;
}
public int getUnitsOnHand(){
return unitsOnHand;
}
public double getPrice(){
return price;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.