From 0711cb9ad74fa0d6aff30d25df79a27f3bd2f317 Mon Sep 17 00:00:00 2001 From: mohamed Date: Mon, 30 Mar 2020 11:43:08 +0200 Subject: [PATCH 1/2] This is the project make the user choose command list by writing numbers or string --- CustomerManagerApp.java | 96 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 CustomerManagerApp.java diff --git a/CustomerManagerApp.java b/CustomerManagerApp.java new file mode 100644 index 0000000..d181195 --- /dev/null +++ b/CustomerManagerApp.java @@ -0,0 +1,96 @@ +import java.util.List; + +public class CustomerManagerApp { + + // declare class variables + private static DAO customerDAO = null; + + public static void main(String[] args) { + // display a welcome message + System.out.println("Welcome to the Customer Manager\n"); + + // set the class variables + customerDAO = new CustomerTextFile(); + + // display the command menu + displayMenu(); + + // perform 1 or more actions + String action = ""; + while (!action.equalsIgnoreCase("exit")) { + // get the input from the user + action = Console.getString("Enter a command: "); + System.out.println(); + + if (action.equalsIgnoreCase("list") || action.equalsIgnoreCase("1")) { + displayAllCustomers(); + } else if (action.equalsIgnoreCase("add") || action.equalsIgnoreCase("2")) { + addCustomer(); + } else if (action.equalsIgnoreCase("del") || action.equalsIgnoreCase("delete") || action.equalsIgnoreCase("3")) { + deleteCustomer(); + } else if (action.equalsIgnoreCase("help") || action.equalsIgnoreCase("menu") || action.equalsIgnoreCase("4")) { + displayMenu(); + } else if (action.equalsIgnoreCase("exit") || action.equalsIgnoreCase("5")) { + System.out.println("Bye.\n"); + } else { + System.out.println("Error! Not a valid command.\n"); + } + } + } + + public static void displayMenu() { + System.out.println("COMMAND MENU. You can write the string name or the number."); + System.out.println("list => 1 - List all customers"); + System.out.println("add => 2 - Add a customer"); + System.out.println("del => 3 - Delete a customer"); + System.out.println("help => 4 - Show this menu"); + System.out.println("exit => 5 - Exit this application\n"); + } + + public static void displayAllCustomers() { + System.out.println("CUSTOMER LIST"); + + List customers = customerDAO.getAll(); + Customer c; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < customers.size(); i++) { + c = customers.get(i); + sb.append(StringUtils.padWithSpaces( + c.getName(), 27)); + sb.append(c.getEmail()); + sb.append("\n"); + } + System.out.println(sb.toString()); + } + + public static void addCustomer() { + String firstName = Console.getLine("Enter first name: "); + String lastName = Console.getString("Enter last name: "); + String email = Console.getString("Enter customer email: "); + + Customer customer = new Customer(); + customer.setFirstName(firstName); + customer.setLastName(lastName); + customer.setEmail(email); + customerDAO.add(customer); + + System.out.println(); + System.out.println(firstName + " " + lastName + + " has been added.\n"); + } + + public static void deleteCustomer() { + String email = Console.getString("Enter email to delete: "); + + Customer c = customerDAO.get(email); + + System.out.println(); + if (c != null) { + customerDAO.delete(c); + System.out.println(c.getName() + + " has been deleted.\n"); + } else { + System.out.println("No customer matches that email.\n"); + } + } +} \ No newline at end of file From 572077b608c1dca30c07985be81d3c5eac523d86 Mon Sep 17 00:00:00 2001 From: mohamed Date: Mon, 30 Mar 2020 11:44:04 +0200 Subject: [PATCH 2/2] This file has the required things --- student.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 student.md diff --git a/student.md b/student.md new file mode 100644 index 0000000..6171c48 --- /dev/null +++ b/student.md @@ -0,0 +1,4 @@ +** Mohamed Ahmed Mohamed Ali Shehata ** + + +* Section => 4 * \ No newline at end of file