Welcome to the Customer Maintenance application COMMAND MENU list - List all cus
ID: 3547348 • Letter: W
Question
Welcome to the Customer Maintenance application
COMMAND MENU
list - List all customers
add - Add a customer
del - Delete a customer
help - Show this menu
exit - Exit this application
Enter a command: list
CUSTOMER LIST
frank46@hotmail.com Frank Jones
sarah_smith@yahoo.com Sarah Smith
Enter a command: add
Enter customer email address: test@gmail.com
Enter first name: text
Enter last name: test
text test was added to the database.
Enter a command: list
CUSTOMER LIST
frank46@hotmail.com Frank Jones
sarah_smith@yahoo.com Sarah Smith
test@gmail.com text test
Enter a command: del
Enter customer email to delete: test@gmail.com
text test was deleted from the database.
Enter a command: list
CUSTOMER LIST
frank46@hotmail.com Frank Jones
sarah_smith@yahoo.com Sarah Smith
Enter a command: exit
Bye.
Explanation / Answer
Here is the code import java.util.Scanner; import java.util.ArrayList; public class CustomerMaintApp implements CustomerConstants { // declare class variables private static CustomerDAO customerDAO = null; private static Scanner sc = null; public static void main(String[] args) { // display a welcome message System.out.println("Welcome to the Customer Maintenance application "); // set the class variables customerDAO = DAOFactory.getCustomerDAO(); 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")) displayAllCustomers(); else if (action.equalsIgnoreCase("add")) addCustomer(); else if (action.equalsIgnoreCase("del") || action.equalsIgnoreCase("delete")) deleteCustomer(); 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 customers"); System.out.println("add - Add a customer"); System.out.println("del - Delete a customer"); System.out.println("help - Show this menu"); System.out.println("exit - Exit this application "); } public static void displayAllCustomers() { System.out.println("CUSTOMER LIST"); ArrayList customers = customerDAO.getCustomers(); Customer c = null; StringBuilder sb = new StringBuilder(); for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.