-
Notifications
You must be signed in to change notification settings - Fork 1
/
MobilePhoneSet.java
62 lines (49 loc) · 1.25 KB
/
MobilePhoneSet.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
import java.util.*;
public class MobilePhoneSet {
Myset set1 = new Myset();
public boolean MobileIsEmpty() {
return set1.IsEmpty();
}
public boolean MobileIsMember(MobilePhone m) {
return set1.IsMember(m);
}
public void MobileInsert(MobilePhone m) {
set1.Insert(m);
}
public void MobileDelete(MobilePhone m) {
set1.Delete(m);
}
public MobilePhoneSet MobileUnion(MobilePhoneSet a) {
MobilePhoneSet s = new MobilePhoneSet();
s.set1 = set1.Union(a.set1);
return s;
}
public MobilePhoneSet MobileIntersection(MobilePhoneSet a) {
MobilePhoneSet s = new MobilePhoneSet();
s.set1 = set1.Intersection(a.set1);
return s;
}
public int numberOfMobiles(){
return set1.numberOfObjects();
}
public MobilePhone nthMobile(int n){
return (MobilePhone)(set1.nthObject(n));
}
public MobilePhone findMobileInSet(int n){
for (int i = 0; i < numberOfMobiles(); i++) {
if(nthMobile(i).mobileNumber() == n)
return nthMobile(i);
}
return null;
}
public String printAll(int n){
String res;
res = "queryMobilePhoneSet "+ n +": ";
for (int i = 0; i < numberOfMobiles(); i++) {
res = res + nthMobile(i).mobileNumber();
if(i < numberOfMobiles() - 1)
res = res + ", ";
}
return res;
}
}