Question: I have the code for my Inventory Manager class and my Product class. Based off this code, I need someone to help me write my

I have the code for my Inventory Manager class and my Product class. Based off this code, I need someone to help me write my 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! Thanks in advance

InventoryManager.java

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

public class InventoryManager {

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

}

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

}

public void addProduct(Product p) { List 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(); } products.add(p); try { CollectionFileStorageUtility.save(products, Product.class); } catch (IOException e) { e.printStackTrace(); } }

public void updateProduct(Product p) { List 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 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,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; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!