-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh14Ex2.java
More file actions
96 lines (84 loc) · 2.12 KB
/
Ch14Ex2.java
File metadata and controls
96 lines (84 loc) · 2.12 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.*;
public class Ch14Ex2
{
public static void main(String args[])
{
ArrayList<Contact> contactList = new ArrayList<Contact>();
Scanner input = new Scanner(System.in);
while(true)
{
System.out.println("1: Add Contact");
System.out.println("2: Display Contacts");
System.out.println("3: Find Contact");
System.out.println("4: Delete Contact");
System.out.println("0: Exit");
int sel = input.nextInt();
input.nextLine();
System.out.println();
if(sel == 0)
break;
switch(sel)
{
case 1:
System.out.print("First name: ");
String f = input.nextLine();
System.out.print("Last name: ");
String l = input.nextLine();
System.out.print("Phone number: ");
String p = input.nextLine();
System.out.print("Email address: ");
String e = input.nextLine();
contactList.add(new Contact(f, l, p, e));
break;
case 2:
for(Contact con: contactList)
con.printC();
break;
case 3:
System.out.println("Info to Find: ");
String info = input.nextLine();
Contact con = findPerson(contactList, info);
if(con != null)
con.printC();
else
System.out.println("Nothing Here");
break;
case 4:
System.out.println("Info to Find: ");
String inf = input.nextLine();
Contact cont = findPerson(contactList, inf);
if(cont != null)
{
cont.printC();
System.out.println("Confirm: Y/N");
String del = input.nextLine();
System.out.println();
if(del.equalsIgnoreCase("y"))
{
contactList.remove(cont);
}
}
else
System.out.println("Nothing Here");
break;
}
}
input.close();
}
private static Contact findPerson(ArrayList<Contact> contactList, String info)
{
Contact c = null;
for(Contact con: contactList)
{
if(contactList.get(i).getFirstName().contains(info))
c = contactList.get(i);
if(contactList.get(i).getLastName().contains(info))
c = contactList.get(i);
if(contactList.get(i).getPhone().contains(info))
c = contactList.get(i);
if(contactList.get(i).getEmail().contains(info))
c = contactList.get(i);
}
return c;
}
}