forked from okaram/IntroJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryExample.java
More file actions
53 lines (41 loc) · 1.14 KB
/
Copy pathDirectoryExample.java
File metadata and controls
53 lines (41 loc) · 1.14 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
package karamo;
import java.util.*;
public class DirectoryExample {
static class Contact {
public String name, email, phone;
public Contact(String name, String email, String phone) {
this.name=name;
this.email=email;
this.phone=phone;
}
@Override
public String toString() {
return name + "- " + email + " - " + phone;
}
}
static class Directory {
Map<String, Contact> contacts=new HashMap<String,Contact>();
public void addContact(Contact c) {
contacts.put( c.name, c);
}
public Contact findByName(String name) {
return contacts.get(name);
}
public List<Contact> getAllContacts() {
return new ArrayList<Contact>(contacts.values());
}
}
public static void main(String args[]) {
Directory d=new Directory();
d.addContact(c1);
d.addContact(c2);
d.addContact(c3);
System.out.println(d.findByName("Orlando K"));
for(Contact c : d.getAllContacts() ) {
System.out.println(c);
}
}
}