Skip to content

Commit ccdea6e

Browse files
committed
aula18 phonebook
1 parent 86179f2 commit ccdea6e

File tree

6 files changed

+125
-0
lines changed

6 files changed

+125
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/untitled/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
public class Contact {
3+
private String name;
4+
private Integer phone;
5+
private String location;
6+
7+
public Contact(String name)
8+
{
9+
this.name = name;
10+
}
11+
public Contact(String name, Integer phone, String location)
12+
{
13+
this.name = name;
14+
this.phone = phone;
15+
this.location = location;
16+
}
17+
18+
public String getName() {
19+
return name;
20+
}
21+
22+
public void setName(String name) {
23+
this.name = name;
24+
}
25+
26+
public Integer getPhone() {
27+
return phone;
28+
}
29+
30+
public void setPhone(Integer phone) {
31+
this.phone = phone;
32+
}
33+
34+
public String getLocation() {
35+
return location;
36+
}
37+
38+
public void setLocation(String location) {
39+
this.location = location;
40+
}
41+
42+
@Override
43+
public String toString() {
44+
return "Contact{" +
45+
"name='" + name + '\'' +
46+
", phone=" + phone +
47+
", location='" + location + '\'' +
48+
'}';
49+
}
50+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
2+
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
3+
public class MainTester {
4+
public static void main(String[] args) {
5+
6+
}
7+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
4+
public class PhoneBook {
5+
private List<Contact> allContacts;
6+
7+
public PhoneBook() {
8+
allContacts = new ArrayList<Contact>();
9+
}
10+
11+
public boolean addContact(Contact contact) {
12+
allContacts.add(contact);
13+
return true;
14+
}
15+
16+
public boolean updateContact(Contact contact, int idx) {
17+
if (idx < 0 && idx < allContacts.size()) {
18+
allContacts.set(idx, contact);
19+
return true;
20+
}
21+
return false;
22+
}
23+
24+
public boolean removeContact(int idx) {
25+
if (idx < 0 && idx < allContacts.size()) {
26+
allContacts.remove(idx);
27+
return true;
28+
}
29+
return false;
30+
}
31+
32+
public void showAll() {
33+
for(Contact contact : allContacts) {
34+
System.out.printf("%s", contact.toString());
35+
}
36+
}
37+
38+
public List<Contact> searchContact(String name) {
39+
List<Contact> result = new ArrayList<Contact>();
40+
for (Contact contact : allContacts) {
41+
if (contact.getName().equalsIgnoreCase(name))
42+
result.add(contact);
43+
}
44+
return result;
45+
}
46+
}
Binary file not shown.

0 commit comments

Comments
 (0)