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

Product Inventory Java Application Imagine that you have been hired to write an

ID: 3537636 • Letter: P

Question

Product Inventory Java Application

Imagine that you have been hired to write an object-oriented Java Web application that will handle a company%u2019s product inventory. Your application must interface with a database (you decide the database that you want to work with) that will allow the user to.  

1.Create an object-oriented Java Web application that:
a. displays the entire product inventory to the screen, including the product ID, name, description, and quantity.
b. allows for a product to be searched by the product ID or product name.
c. allows for new products to be added to the inventory.
d. allows for existing products to be edited.
e. allows for existing products to be deleted.

Explanation / Answer

POJO :

package org.students;

import java.util.Enumeration;
import java.util.Hashtable;

public class Company {
   Hashtable<String, Product> inventory = new Hashtable<String, Product>();
   public void addProduct(int productID, String productName, String description, int quantity){
       Product p = new Product();
       p.setProductID(productID);
       p.setProductName(productName);
       p.setDescription(description);
       p.setQuantity(quantity);
      
       String key = "productID : "+p.getProductID()+" | productName : "+p.getProductName();
       inventory.put(key, p);
   }
  
   public void deleteProduct(Integer productID){
       Product prod = search(productID);
       if(prod != null){
           String key = "productID : "+productID+" | productName : "+prod.getProductName();
           inventory.remove(key);
       }
   }
  
   public void editProduct(Integer productID, String description, int quantity){
       Product prod = search(productID);
       if(prod != null){
           prod.setDescription(description);
           prod.setQuantity(quantity);
       }
   }
  
   public String list(){
       String data = "ProductID ProductName Description quantity<br>";
       Enumeration<Product> e = inventory.elements();
       while(e.hasMoreElements()){
           Product prod = e.nextElement();
           data += prod.getProductID()+" "+prod.getProductName()+" "+prod.getDescription()+" "+prod.getQuantity()+"<br>";
       }
       return data;
   }
  
   public Product search(Object search){
       String key = "";
       if(search instanceof Integer){
           key = "productID : "+((Integer)search);
       }else if(search instanceof String){
           key = "productName : "+((String)search);
       }
       for(String k : inventory.keySet()){
           if(k.indexOf(key) >= 0){
               return inventory.get(k);
           }
       }
       return null;
   }
}

class Product{
   int productID;
   String productName;
   String description;
   int quantity;
   public int getProductID() {
       return productID;
   }
   public void setProductID(int productID) {
       this.productID = productID;
   }
   public String getProductName() {
       return productName;
   }
   public void setProductName(String productName) {
       this.productName = productName;
   }
   public String getDescription() {
       return description;
   }
   public void setDescription(String description) {
       this.description = description;
   }
   public int getQuantity() {
       return quantity;
   }
   public void setQuantity(int quantity) {
       this.quantity = quantity;
   }
}

Process.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="list.html"></jsp:include>
<%
   if(session.getAttribute("inventory") == null){
       org.students.Company p = new org.students.Company();
       session.setAttribute("inventory", p);
   }
   org.students.Company comp = session.getAttribute("inventory");
   Integer productID;
   if(request.getParameter("productID") != null)
   productID = Integer.valueOf(request.getParameter("productID"));
   String productName = request.getParameter("productName");
   String description = request.getParameter("description");
   int quantity = -1;
   if(request.getParameter("quantity") != null)
   quantity = Integer.parseInt(request.getParameter("quantity"));
   if(request.getParameter("list") != null){
       out.print(comp.list());
   }else if(request.getParameter("add")){
       comp.addProduct(productID, productName, description, quantity);
       out.print("successfully added");
   }else if(request.getParameter("edit")){
       comp.editProduct(productID, description, quantity);
   }else if(request.getParameter("delete")){
       comp.deleteProduct(productID);
       out.print("deleted successfully");
   }
%>
</body>
</html>


list.html

<a href="one.jsp?list=">list</a><br>
<a href="add.html">add</a><br>
<a href="delete.html">delete</a><br>
<a href="edit.html">add</a><br>


add.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
   <form action="one.jsp">
       productID:<input type="text" name="productID" /><br>
       productName:<input type="text" name="productName" /><br>
       description<input type="text" name="description" /><br>
       quantity<input type="text" name="quantity" /><br>
       <input type="submit" name="add" />
   </form>
</body>
</html>


edit.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
   <form action="one.jsp">
       productID:<input type="text" name="productID" /><br>
       description<input type="text" name="description" /><br>
       quantity<input type="text" name="quantity" /><br>
       <input type="submit" name="edit" />
   </form>
</body>
</html>

delete.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
   <form action="one.jsp">
       productID:<input type="text" name="productID" /><br>
       <input type="submit" name="delete" />
   </form>
</body>
</html>

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