From a81f90781d2149ef6bece7ad120d61cb36448ad9 Mon Sep 17 00:00:00 2001 From: Omar Elsayed <61805234+omarelsayed100@users.noreply.github.com> Date: Mon, 13 Apr 2020 21:22:24 +0200 Subject: [PATCH 1/5] Create OS TASK --- OS TASK | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 OS TASK diff --git a/OS TASK b/OS TASK new file mode 100644 index 0000000..f8df940 --- /dev/null +++ b/OS TASK @@ -0,0 +1,191 @@ +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")) { + + 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")) { + + System.out.println("Bye.\n"); + + } else { + + System.out.println("Error! Not a valid command.\n"); + + } + + } + + } + + + + 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\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"); + + } + + } + +} From 9dd522ef0aba13c6a9cf8d54455d4dc19279d998 Mon Sep 17 00:00:00 2001 From: Omar Elsayed <61805234+omarelsayed100@users.noreply.github.com> Date: Mon, 13 Apr 2020 21:26:20 +0200 Subject: [PATCH 2/5] Update OS TASK --- OS TASK | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/OS TASK b/OS TASK index f8df940..3075cce 100644 --- a/OS TASK +++ b/OS TASK @@ -46,23 +46,23 @@ public class CustomerManagerApp { - if (action.equalsIgnoreCase("list")) { + if (action.equalsIgnoreCase("1")) { displayAllCustomers(); - } else if (action.equalsIgnoreCase("add")) { + } else if (action.equalsIgnoreCase("2")) { addCustomer(); - } else if (action.equalsIgnoreCase("del") || action.equalsIgnoreCase("delete")) { + } else if (action.equalsIgnoreCase("3") || action.equalsIgnoreCase("delete")) { deleteCustomer(); - } else if (action.equalsIgnoreCase("help") || action.equalsIgnoreCase("menu")) { + } else if (action.equalsIgnoreCase("4") || action.equalsIgnoreCase("menu")) { displayMenu(); - } else if (action.equalsIgnoreCase("exit")) { + } else if (action.equalsIgnoreCase("5")) { System.out.println("Bye.\n"); @@ -82,15 +82,15 @@ public class CustomerManagerApp { System.out.println("COMMAND MENU"); - System.out.println("list - List all customers"); + System.out.println("1 - List all customers"); - System.out.println("add - Add a customer"); + System.out.println("2 - Add a customer"); - System.out.println("del - Delete a customer"); + System.out.println("3 - Delete a customer"); - System.out.println("help - Show this menu"); + System.out.println("4 - Show this menu"); - System.out.println("exit - Exit this application\n"); + System.out.println("5 - Exit this application\n"); } From e8e6e370e8bde38691a3a8d51a9862b5c1a48f45 Mon Sep 17 00:00:00 2001 From: Omar Elsayed <61805234+omarelsayed100@users.noreply.github.com> Date: Mon, 13 Apr 2020 21:31:06 +0200 Subject: [PATCH 3/5] Create Name & Sec --- Name & Sec | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Name & Sec diff --git a/Name & Sec b/Name & Sec new file mode 100644 index 0000000..05b11b2 --- /dev/null +++ b/Name & Sec @@ -0,0 +1,2 @@ +Omar Elsayed Salim Badawi +Section 4 From d3f62a9fc7bac6d38bee7c9cb85f14ce21e9db31 Mon Sep 17 00:00:00 2001 From: Omar Elsayed <61805234+omarelsayed100@users.noreply.github.com> Date: Mon, 13 Apr 2020 21:44:51 +0200 Subject: [PATCH 4/5] Rename Name & Sec to Student.md --- Name & Sec => Student.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Name & Sec => Student.md (100%) diff --git a/Name & Sec b/Student.md similarity index 100% rename from Name & Sec rename to Student.md From 33cdeca0fd75182872f350f0028eb3c10ea49682 Mon Sep 17 00:00:00 2001 From: Omar Elsayed <61805234+omarelsayed100@users.noreply.github.com> Date: Mon, 13 Apr 2020 21:52:19 +0200 Subject: [PATCH 5/5] Update Student.md --- Student.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Student.md b/Student.md index 05b11b2..0fdb0a6 100644 --- a/Student.md +++ b/Student.md @@ -1,2 +1,5 @@ -Omar Elsayed Salim Badawi +NAME / Omar Elsayed Salim Badawi ++ ++ ++ Section 4