-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMobilePhoneSet.java
More file actions
43 lines (32 loc) · 1.07 KB
/
MobilePhoneSet.java
File metadata and controls
43 lines (32 loc) · 1.07 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
public class MobilePhoneSet extends Myset{
/*
stores MobilePhone objects in a Myset.
*/
public MobilePhoneSet(){
super();
}
public MobilePhone searchPhone(int id) throws MobilePhoneNotFoundException{
/*
Returns mobile phone with identifier id.
Throws exception if phone not found
*/
MyLinkedList.Node itr = myset.head;
MobilePhone mobile = null;
if(itr!=null){
mobile = (MobilePhone) itr.data;
}
while(itr!=null && (mobile.number() != id)){
itr = itr.next;
if(itr!=null){
mobile = (MobilePhone)itr.data;
}
}
if(mobile == null){
throw new MobilePhoneNotFoundException("Error - No mobile phone with identifier "+id+" found in the network");
}
if(mobile.number() != id){
throw new MobilePhoneNotFoundException("Error - No mobile phone with identifier "+id+" found in the network");
}
return mobile;
}
}