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

All of the code is below Add code to the ProductMaintApp class that lets the use

ID: 3696375 • Letter: A

Question

All of the code is below

Add code to the ProductMaintApp class that lets the user update an existing product. To do that, you'll need to add an update command to the list of commands, you'll need to add an updateProduct method that provides for updating a product, and you'll need to add an else if clause to the if statement in the main method that executes the updateProduct method if the user enters the update command.

The updateProduct method should start by getting a valid product code from the user. Then, it should ask the user if he wants to update the product's description or price. Depending on the user's response, it should then accept a new description or price from the user. Finally, it should call the updateProduct method of the ProductDAO object to update the product and print a line that indicates the update operation that was performed.

All of the code is below

http://pastebin.com/miAEbenx productwriter

http://pastebin.com/f1t91Xhv productmaintapp

http://pastebin.com/Wdcgw3P3

http://pastebin.com/jeCpLfgL validator

http://pastebin.com/twAQntCA DAOFactory

http://pastebin.com/LgBReAAp Product

http://pastebin.com/tWqFjt2h productconstants

http://pastebin.com/a0S3Sdud productreader

http://pastebin.com/MjjS4XDN productdao

Explanation / Answer

##Productmaintapp code

import java.util.Scanner;

public class ProductMaintApp
{
// declare two class variables
private static ProductDAO productDAO = null;
private static Scanner sc = null;

public static void main(String args[])
{
System.out.println("Welcome to the Product Maintenance application ");

// set the class variables
productDAO = DAOFactory.getProductDAO();
sc = new Scanner(System.in);

// display the command menu
displayMenu();

// perform 1 or more actions
String action = "";
while (!action.equalsIgnoreCase("exit"))
{
// get the input from the user
action = Validator.getString(sc,
"Enter a command: ");
System.out.println();

if (action.equalsIgnoreCase("list"))
displayAllProducts();
else if (action.equalsIgnoreCase("add"))
addProduct();
else if (action.equalsIgnoreCase("update"))
updateProduct();
else if (action.equalsIgnoreCase("del") ||
action.equalsIgnoreCase("delete"))
deleteProduct();
else if (action.equalsIgnoreCase("help") ||
action.equalsIgnoreCase("menu"))
displayMenu();
else if (action.equalsIgnoreCase("exit"))
System.out.println("Bye. ");
else
System.out.println("Error! Not a valid command. ");
}
}

public static void displayMenu()
{
System.out.println("COMMAND MENU");
System.out.println("list - List all products");
System.out.println("add - Add a product");
System.out.println("update - Update a product");
System.out.println("del - Delete a product");
System.out.println("help - Show this menu");
System.out.println("exit - Exit this application ");
}

public static void displayAllProducts()
{
System.out.println("PRODUCT LIST");
System.out.println(productDAO.getProductsString());
}

public static void addProduct()
{
String code = Validator.getString(
sc, "Enter product code: ");
String description = Validator.getLine(
sc, "Enter product description: ");
double price = Validator.getDouble(
sc, "Enter price: ");

Product product = new Product();
product.setCode(code);
product.setDescription(description);
product.setPrice(price);
productDAO.addProduct(product);

System.out.println();
System.out.println(description
+ " has been added. ");
}
  
public static void updateProduct()
{
String code = Validator.getString(sc,
"Enter product code to update: ");
      
       sc = new Scanner(System.in);
       Product p = new Product();
       product.setCode(code);
      
       System.out.println("type d to update description and type description or type p to update price and type price");
       Scanner input = new Scanner(System.in);
  
      
       if(input == "d")
       {   Scanner description = new Scanner(System.in);
           product.setDescription(description)
      
       }
       if(input== " p")
       {
           Scanner price = new Scanner(System.in);
           product.setPrice(price);
       }
}

public static void deleteProduct()
{
String code = Validator.getString(sc,
"Enter product code to delete: ");

Product p = productDAO.getProduct(code);

System.out.println();
if (p != null)
{
productDAO.deleteProduct(p);
System.out.println(p.getDescription()
+ " has been deleted. ");
}
else
{
System.out.println("No product matches that product code. ");
}
}
}

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