|
| 1 | +import java.util.*; |
| 2 | + |
| 3 | +public class Customer { |
| 4 | + static int id=1; |
| 5 | + static Map<Integer, Customer> allCustomers = new HashMap<>(); |
| 6 | + static Scanner input = new Scanner(System.in); |
| 7 | + int Customer_id; |
| 8 | + String Customer_name; |
| 9 | + String Customer_Contact; |
| 10 | + List<Integer> CartItems; |
| 11 | + List<String> CustomerInvoices; |
| 12 | + |
| 13 | + public Customer(String customerName,String customerContact) { |
| 14 | + this.Customer_id = id++; |
| 15 | + this.Customer_name = customerName; |
| 16 | + this.Customer_Contact = customerContact; |
| 17 | + this.CartItems = new ArrayList<>(); |
| 18 | + this.CustomerInvoices = new ArrayList<>(); |
| 19 | + } |
| 20 | + |
| 21 | + public static void CustomerControlPanel() { |
| 22 | + System.out.println("1 -> Create New Customer\n2 -> Update Customer Details\n3 -> Delete Customer\n4 -> List All Customers\n5 -> Back\nChoice :"); |
| 23 | + Scanner input = new Scanner(System.in); |
| 24 | + int AdminSelection = input.nextInt(); |
| 25 | + switch (AdminSelection){ |
| 26 | + case 1: |
| 27 | + CreateNewCustomer(); |
| 28 | + break; |
| 29 | + case 2: |
| 30 | + System.out.println("Enter Customer Id"); |
| 31 | + int customerId = input.nextInt(); |
| 32 | + if(!isExistingCustomer(customerId)) CustomerControlPanel(); |
| 33 | + updateCustomerDetails(customerId); |
| 34 | + break; |
| 35 | + case 3: |
| 36 | + System.out.println("Enter Customer Id"); |
| 37 | + customerId = input.nextInt(); |
| 38 | + if(!isExistingCustomer(customerId)) CustomerControlPanel(); |
| 39 | + allCustomers.remove(customerId); |
| 40 | + System.out.println("Successfully Deleted!"); |
| 41 | + break; |
| 42 | + case 4: |
| 43 | + printAllCustomers(); |
| 44 | + break; |
| 45 | + case 5: |
| 46 | + AdminControlPanel.AdminControls("admin", "password"); |
| 47 | + break; |
| 48 | + } |
| 49 | + CustomerControlPanel(); |
| 50 | + } |
| 51 | + |
| 52 | + private static boolean isExistingCustomer(int customerId) { |
| 53 | + boolean isExistingUser = allCustomers.containsKey(customerId); |
| 54 | + if(!isExistingUser) System.out.println("User Not Found!"); |
| 55 | + return isExistingUser; |
| 56 | + } |
| 57 | + |
| 58 | + private static void updateCustomerDetails(int customerId) { |
| 59 | + Customer customerDetails = allCustomers.get(customerId); |
| 60 | + if(!isExistingCustomer(customerId)) CustomerControlPanel(); |
| 61 | + System.out.println("1 -> Update Name\n 2 -> Update Contact\n3 -> Update Name and Contact\n4 -> Back\nChoice :"); |
| 62 | + int choice = input.nextInt(); |
| 63 | + switch (choice){ |
| 64 | + case 1: |
| 65 | + System.out.println("Enter Name:"); |
| 66 | + String customerName = input.next(); |
| 67 | + customerDetails.Customer_name = customerName; |
| 68 | + break; |
| 69 | + case 2: |
| 70 | + System.out.println("Enter Contact:"); |
| 71 | + String customerContact = input.next(); |
| 72 | + customerDetails.Customer_Contact = customerContact; |
| 73 | + break; |
| 74 | + case 3: |
| 75 | + System.out.println("Enter Name and Contact :"); |
| 76 | + customerName = input.next(); |
| 77 | + customerContact = input.next(); |
| 78 | + customerDetails.Customer_name = customerName; |
| 79 | + customerDetails.Customer_Contact = customerContact; |
| 80 | + break; |
| 81 | + case 4: |
| 82 | + break; |
| 83 | + } |
| 84 | + System.out.println("Customer Details Updated for "+customerDetails.Customer_name); |
| 85 | + CustomerControlPanel(); |
| 86 | + } |
| 87 | + |
| 88 | + private static void printAllCustomers() { |
| 89 | + System.out.println( |
| 90 | + "======================= Customers List ==============\n== CustomerId == Customer Name == Customer Contact =="); |
| 91 | + for (Customer currentCustomer : allCustomers.values()) { |
| 92 | + System.out.println(currentCustomer.Customer_id+" "+currentCustomer.Customer_name+" "+currentCustomer.Customer_Contact); |
| 93 | + } |
| 94 | + System.out.println("======================= End Of List ==============\n"); |
| 95 | + } |
| 96 | + |
| 97 | + public static void CreateNewCustomer() { |
| 98 | + System.out.println("Enter Customer Name and Customer Contact"); |
| 99 | + String customerName = input.next(); |
| 100 | + String customerContact = input.next(); |
| 101 | + Customer newCustomer = new Customer(customerName, customerContact); |
| 102 | + allCustomers.put(newCustomer.Customer_id, newCustomer); |
| 103 | + System.out.println("Customer Id Created for "+newCustomer.Customer_name+"\nCustomerId : "+newCustomer.Customer_id); |
| 104 | + } |
| 105 | +} |
0 commit comments