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

I have the code for my InventoryManager class and my Product class. Based off th

ID: 3662787 • Letter: I

Question

I have the code for my InventoryManager class and my Product class. Based off this code, I need someone to write the *InventoryApp Class* which is a simple application which uses a menu , a Scanner object, and an InventoryManager OBJECT to let users view, add, update, and remove product data. Be sure to use a loop so that the user can perform as many menu choices as they like before they choose to quit. ALL HELP is greatly appreciated! PLEASE DON'T COPY THE CODE I HAVE AS AN ANSWER. Thanks in advance.

InventoryManager.java

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class InventoryManager {

  
   public List<Product> getProductList() {
       List<Product> products=null;
       try {
           products=(List<Product>) CollectionFileStorageUtility.load(Product.class);
       } catch (ClassNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
       return products;

   }

   public Product getProduct(String upc)
   {
       List<Product> products = getProductList();
       for (Product pro : products) {
           if (pro.getUpc().equals(upc)) {
               return pro;
           }
       }
       return null;

   }

   public void addProduct(Product p)
   {
       List<Product> products = getProductList();
       if(products!=null)
       {
           for (Product pro : products)
           {
               if (pro.getUpc().equals(p.getUpc()))
               {
                   System.out.println("A product with given upc alredy exist,cannot duplicate upc");
                   return;
               }
           }
       }
       else
       {
           products=new ArrayList<Product>();
       }
       products.add(p);
       try
       {
           CollectionFileStorageUtility.save(products, Product.class);
       }
       catch (IOException e)
       {
           e.printStackTrace();
       }
   }

   public void updateProduct(Product p)
   {
       List<Product> products = getProductList();
       if(products==null)
       {
           return;
       }
       else
       {
           for (Product pro : products)
           {
               if (pro.getUpc().equals(p.getUpc()))
               {
                   if (!p.getLongDetails().isEmpty())
                   {
                       pro.setLongDetails(p.getLongDetails());
                   }
                   if (p.getPrice()!=null)
                   {
                       pro.setPrice(p.getPrice());
                   }
                   if (!p.getShortDetails().isEmpty())
                   {
                       pro.setShortDetails(p.getShortDetails());
                   }
                   if (pro.getStock()!=0)
                   {
                       pro.setStock(p.getStock());
                   }
                   return;
               }
           }
           System.out.println("A product with given upc does not exist");
       }
      
   }

   public void removeProduct(String upc)
   {
       List<Product> products = getProductList();
       if(products==null)
       {
           return;
       }
       else
       {
           for (Product pro : products)
           {
               if (pro.getUpc().equals(upc))
               {
                   products.remove(pro);
                   return;
               }
           }
           System.out.println("A product with given upc does not exist");
       }
      
   }
}

Product.java

import java.io.Serializable;
import java.math.BigDecimal;


public class Product implements Comparable<Product>,Serializable {

   private String upc;
   private String shortDetails;
   private String longDetails;private BigDecimal price;
   private int stock;
  
   public String getUpc() {
       return upc;
   }
   public void setUpc(String upc) {
       this.upc = upc;
   }
   public String getShortDetails() {
       return shortDetails;
   }
   public void setShortDetails(String shortDetails) {
       this.shortDetails = shortDetails;
   }
   public String getLongDetails() {
       return longDetails;
   }
   public void setLongDetails(String longDetails) {
       this.longDetails = longDetails;
   }
   public BigDecimal getPrice() {
       return price;
   }
   public void setPrice(BigDecimal price) {
       this.price = price;
   }
   public int getStock() {
       return stock;
   }
   public void setStock(int stock) {
       this.stock = stock;
   }
  
   public int compareTo(Product p) {
       if(this.getUpc().equals(p.getUpc()))
       {
           return 1;
       }
       return 0;
   }

  
}

Explanation / Answer

I have written this below InventoryApp class for menu driven java code as per given in problem statement.
This below code will display the menu and select the operation according to user accpetace.

import java.util.Scanner;
public class InventoryApp
{
   public static void main(String[] args)
   {

       int option,quit;
       Scanner sc = new Scanner(System.in);
       while(true)
       {
           System.out.println("1.View 2. Add 3. Update 4. Remove and 5. Quit Product Menu:");
           System.out.println("Enter your Selection from the Above Menu Options:");
           option = sc.nextInt();
           switch (option)
           {
               case 1:
                   System.out.println("View the Product");
                   // Add method here
                   break;
               case 2:
                   System.out.println("Add the Product");
                   // Add method Here
                   break;
               case 3:
                   System.out.println("Update the Product");
                   // Add method Here
                   break;
               case 4:
                   System.out.println("Remove the Product");
                   // Add method Here
                   break;
               case 5:
                   System.out.println("Exit from the Menu");                  
                   System.exit(0);                  
           }
       }
  
   }
}