-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactStore.java
84 lines (78 loc) · 3.47 KB
/
ContactStore.java
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.ArrayList;
import java.util.Scanner;
public class ContactStore {
private ArrayList<AddressBook> contactList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
public ArrayList<AddressBook> getContactList() {
return contactList;
}
public void add(AddressBook contact) {
contactList.add(contact);
}
void edit() {
System.out.println("Enter name of contact you want to edit");
String name = scanner.nextLine();
for (AddressBook addressBook : contactList) {
if (addressBook.getFirstName().equalsIgnoreCase(name)) {
boolean check = true;
while (check) {
System.out.println("Edit Options 1.firstName\n 2.lastName\n 3.address\n 4.city\n 5.state\n 6.zip\n 7.phonenumber\n 8.email\n 9.exit");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1 -> {
System.out.println("Enter your new firstName :");
String firstName = scanner.nextLine();
addressBook.setFirstName(firstName);
}
case 2 -> {
System.out.println("Enter your new lastName : ");
String lastName = scanner.nextLine();
addressBook.setLastName(lastName);
}
case 3 -> {
System.out.println("Enter your new address :");
String address = scanner.nextLine();
addressBook.setAddress(address);
}
case 4 -> {
System.out.println("Enter your new city : ");
String city = scanner.nextLine();
addressBook.setCity(city);
}
case 5 -> {
System.out.println("Enter your new state :");
String state = scanner.nextLine();
addressBook.setCity(state);
}
case 6 -> {
System.out.println("Enter your new zip : ");
String zip = scanner.nextLine();
addressBook.setZip(zip);
}
case 7 -> {
System.out.println("Enter your new phoneNumber :");
String phoneNumber = scanner.nextLine();
addressBook.setPhoneNumber(phoneNumber);
}
case 8 -> {
System.out.println("Enter your new email : ");
String email = scanner.nextLine();
addressBook.setEmail(email);
}
default -> check = false;
}
}
}
}
}
public void remove() {
System.out.println("Enter name of contact you want to delete");
String name = scanner.nextLine();
for (int i = 0; i < contactList.size(); i++) {
if (contactList.get(i).getFirstName().equalsIgnoreCase(name)) {
contactList.remove(contactList.get(i));
}
}
}
}