Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Directions: For this assignment, you will need to create a class called Inventor

ID: 3745953 • Letter: D

Question

Directions: For this assignment, you will need to create a class called Inventoryltem that represents an inventory item in a store. Inventoryltem should have the following characteristics: Inventoryltem Variables: o A String called name using the protected visibility modifier o A double called price using the protected visibility modifier o A private static double called taxRate (initialized to 0) . Constructor o Sets the values for the instance variables name and price: public InventoryItem(String nameIn, double priceIn) Methods: o pub1ic String getName - Returns the customer name o public double calculateCostO ( - Returns the price including tax: price *(1+ taxRate) - Sets the tax rate . Return a String representation with name and price with tax o public static void setTaxRate (double taxRateIn) f o public String toString) f Example: "Computer: $789.02" return name+ ":S" + InventoryItem.setTaxRate (0.08)i inventory! tem item1 = new Inventoryltem ("Birdseed", item1 Birdseed: $8.6292 7.99); InventoryItem item2 new InventoryItem ("Picture", 10.99): item2 Picture: $11.869200000000001 Be sure to unfold these objects on the workbench to verify the field values.

Explanation / Answer

I am sending all the classes asked. Place all the files in same folder.

Feel free comment if there is any doubt. All the best.

1.InventoryItem Class

public class InventoryItem {
   protected String name;
   protected double price;
   private static double taxRate;
   public InventoryItem(String nameIn,double priceIn) {
       name=nameIn;
       price=priceIn;
   }
   public String getName() {
       return name;
   }
   public double calculateCost() {
       return price*(1+taxRate);
   }
   public static void setTaxRate(double taxRateIn) {
       taxRate=taxRateIn;
   }
   public String toString() {
       return name+": $"+calculateCost();
   }
   public static void main(String[] args) {
       InventoryItem.setTaxRate(0.08);
       InventoryItem item1=new InventoryItem("Birdseed",7.99);
       System.out.println(item1.toString());
       InventoryItem item2=new InventoryItem("Picture",10.99);
       System.out.println(item2.toString());
      
   }

}

2.ElectronicsItem Class

public class ElectronicsItem extends InventoryItem{
   protected double weight;
   public static final double SHIPPING_COST=1.5;
   public ElectronicsItem(String nameIn, double priceIn,double weightIn) {
       super(nameIn, priceIn);
       weight=weightIn;
   }
   public double calculateCost() {
       return super.calculateCost()+(SHIPPING_COST*weight);
   }
  
   public static void main(String[] args) {
       InventoryItem.setTaxRate(0.08);
       ElectronicsItem item1=new ElectronicsItem("Monitor",100,10.0);
       System.out.println(item1.toString());
      
      
   }

}

3.OnlineTextItem

public abstract class OnlineTextItem extends InventoryItem{

   public OnlineTextItem(String nameIn, double priceIn) {
       super(nameIn, priceIn);
       // TODO Auto-generated constructor stub
   }
   public double calculateCost() {
       return price;
   }

}

4.OnlineArticle

public class OnlineArticle extends OnlineTextItem{
   private int wordCount;

   public OnlineArticle(String nameIn, double priceIn) {
       super(nameIn, priceIn);
       wordCount=0;
   }
   public void setWordCount(int wordCountIn) {
       wordCount=wordCountIn;
   }  

}

5.OnlineBook

public class OnlineBook extends OnlineTextItem{
   protected String author;
   public OnlineBook(String nameIn, double priceIn) {
       super(nameIn, priceIn);
       author="Author Not Listed";
   }
   public String toString() {
       return name+" - "+author+": $"+calculateCost();
   }
   public void setAuthor(String authorIn) {
       author=authorIn;
   }
   public static void main(String[] args) {
       OnlineBook book=new OnlineBook("A Novel Novel",9.99);
       System.out.println(book.toString());
       book.setAuthor("Jane Lane");
       System.out.println(book.toString());
   }

}

6.InventoryApp

public class InventoryApp {
   public static void main(String[] args) {
       InventoryItem.setTaxRate(0.05);
       InventoryItem item1=new InventoryItem("Oil change kit",39);
       ElectronicsItem item2=new ElectronicsItem("Cordless phone",80,1.8);
       OnlineArticle item3=new OnlineArticle("Java News",8.50);
       item3.setWordCount(700);
       OnlineBook item4=new OnlineBook("Java for Noobs",13.37);
       item4.setAuthor("L.G.Jones");
       System.out.println(item1.toString());
       System.out.println(item2.toString());
       System.out.println(item3.toString());
       System.out.println(item4.toString());
      
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote