Question
Add appropriate descriptive comments to each line of code in the project explaining why the code is in the application. package murach.ui; import murach.business.Product; import
Add appropriate descriptive comments to each line of code in the project explaining why the code is in the application.
package murach.ui;
import murach.business.Product; import murach.db.ProductTextFile; import murach.db.DAO;
import java.util.List;
public class ProductManagerApp { private static DAO
public static void main(String args[]) { System.out.println("Welcome to the Product Manager "); displayMenu();
String action = ""; while (!action.equalsIgnoreCase("exit")) { action = Console.getString("Enter a command: "); System.out.println();
if (action.equalsIgnoreCase("list")) { displayAllProducts(); } else if (action.equalsIgnoreCase("add")) { addProduct(); } else if (action.equalsIgnoreCase("del") || action.equalsIgnoreCase("delete")) { deleteProduct(); } else if (action.equalsIgnoreCase("help") || action.equalsIgnoreCase("menu")) { displayMenu(); } else if (action.equalsIgnoreCase("exit") || action.equalsIgnoreCase("quit")) { 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("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");
List
public static void addProduct() { String code = Console.getString("Enter product code: "); String description = Console.getLine("Enter product description: "); double price = Console.getDouble("Enter price: ");
Product product = new Product(); product.setCode(code); product.setDescription(description); product.setPrice(price); boolean success = productFile.add(product); if (success) { System.out.println(description + " has been added. "); } else { System.out.println(description + " was NOT added. "); } }
public static void deleteProduct() { String code = Console.getString("Enter product code to delete: ");
Product p = productFile.get(code); if (p != null) { boolean success = productFile.delete(p); if (success) { System.out.println(p.getDescription() + " has been deleted. "); } else { System.out.println(p.getDescription() + " was NOT deleted. "); } } else { System.out.println("No product matches that code. "); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started