Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago