Repository navigation
Expand file tree
/
Copy pathContacts.java
More file actions
73 lines (64 loc) · 1.87 KB
/
Copy pathContacts.java
File metadata and controls
73 lines (64 loc) · 1.87 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
import java.util.ArrayList;
public class Contacts {
//housescontacts for the GUI, makes it simpler for user
private ArrayList<String> address;
private ArrayList<String> name;
public Contacts() {
address=new ArrayList<String>();
name=new ArrayList<String>();
}
public void addContact(String name, String address) {
//adds contacts to arraylist
this.address.add(address);
this.name.add(name);
}
public void removeContact(int ind) {
//removes contact from indexes
address.remove(ind);
name.remove(ind);
}
public ArrayList<String> getContacts() {
//returns arraylist of contacts
//in order of name, then address
//e.g. [Bob,192.168.2.1,Charley,127.0.0.1,Cameron,192.222.3.1..etc]
ArrayList<String> contacts=new ArrayList<String>();
int i=0;
for(;i<name.size();i++){
contacts.add(name.get(i));
contacts.add(address.get(i));
}
return contacts;
}
public String getAddress(int ind) {
if (ind>=0 && ind<address.size()) {
return address.get(ind);
}
return null;
}
public String getName(int ind) {
if (ind>=0 && ind<name.size()) {
return name.get(ind);
}
return null;
}
public int indexOfName(String n){
//return index of a given name
return name.indexOf(n);
}
public int indexOfAddress(String a){
//return index of a given address
return address.indexOf(a);
}
public boolean containsAddress(String address){
// If it contains a given address will return true;
if (this.address.size() != 0){
for (int i = 0; i < this.address.size(); i++){
if (this.address.get(i).equals(address)){
return true;
}
}
}
return false;
// will never reach this simply adding it to stop error
}
}