-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCustomerManager.java
More file actions
68 lines (54 loc) · 1.66 KB
/
Copy pathCustomerManager.java
File metadata and controls
68 lines (54 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.ArrayList;
public class CustomerManager {
private ArrayList<Customer> customers = new ArrayList<>();
public ArrayList<Customer> getCustomersList() {
return customers;
}
public void addCustomer(Customer c) {
if (findCustomer(c.customerID) != null){
System.out.print("Customer ID already exists. Please enter a unique ID");
return;
}
customers.add(c);
System.out.print("Customer Added successfully");
}
public void editCustomer(String id, String newName, String newPhone, String newEmail, String newAddress) {
Customer c = findCustomer(id);
if (c == null) {
System.out.println("Customer not found.");
return;
}
c.name = newName;
c.phoneNumber = newPhone;
c.email = newEmail;
c.address = newAddress;
System.out.println("Customer details updated successfully.");
}
public void deleteCustomer(String id) {
Customer c = findCustomer(id);
if (c == null) {
System.out.println("Customer not found.");
return;
}
customers.remove(c);
System.out.println("Customer deleted successfully.");
}
public Customer findCustomer(String id) {
for (Customer c : customers) {
if (c.customerID.equals(id)) {
return c;
}
}
return null;
}
public void viewCustomers() {
if (customers.isEmpty()) {
System.out.println("No customers found.");
return;
}
System.out.println("\n--- Customers ---");
for (Customer c : customers) {
System.out.println(c);
}
}
}