01
02
03
04
05
06
07
08
09
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
|
package horstmann.ch02_mail;
import java.util.ArrayList;
/**
A system of voice mail boxes.
*/
public class MailSystem
{
/**
Constructs a mail system with a given number of mailboxes
@param mailboxCount the number of mailboxes
*/
public MailSystem(int mailboxCount)
{
mailboxes = new ArrayList<Mailbox>();
// Initialize mail boxes.
for (int i = 0; i < mailboxCount; i++)
{
String passcode = "" + (i + 1);
String greeting = "You have reached mailbox " + (i + 1)
+ ". \nPlease leave a message now.";
mailboxes.add(new Mailbox(passcode, greeting));
}
}
/**
Locate a mailbox.
@param ext the extension number
@return the mailbox or null if not found
*/
public Mailbox findMailbox(String ext)
{
int i = Integer.parseInt(ext);
if (1 <= i && i <= mailboxes.size())
return mailboxes.get(i - 1);
else return null;
}
private ArrayList<Mailbox> mailboxes;
}
|