-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMobilePhoneSet.java
60 lines (54 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
import java.util.*;
public class MobilePhoneSet
{
Myset mobileSet;
public MobilePhoneSet()
{
mobileSet = new Myset();
}
public void Insert(MobilePhone mobile)
{
try { mobileSet.Insert(mobile); }
catch(RuntimeException ex)
{
throw new RuntimeException("Error - Mobile phone with identifier " + mobile.number() + " is already present in this resident set");
}
}
public void Delete(MobilePhone mobile)
{
try { mobileSet.Delete(mobile); }
catch(RuntimeException e)
{
throw new RuntimeException("Error - Mobile phone with identifier " + mobile.number() + " is not present in this resident set");
}
}
public MobilePhone getMobile(int m)
{
int n = mobileSet.size();
Object[] objs = mobileSet.getItems();
MobilePhone mobile;
for(int i=0; i<n; i++)
{
mobile = (MobilePhone)objs[i];
if(mobile.number() == m) return mobile;
}
return null;
}
public int[] getMobiles()
{
int n = mobileSet.size();
Vector<Integer> v = new Vector<Integer>();
MobilePhone m;
Object[] objs = mobileSet.getItems();
for(int i=0; i<n; i++)
{
m = (MobilePhone)objs[i];
if(m.status) v.add(m.number());
}
n = v.size();
int[] mobiles = new int[n];
for(int i=0; i<n; i++)
mobiles[i] = v.get(i);
return mobiles;
}
}