01: import java.util.ArrayList;
02: 
03: /**
04:    A system of voice mail boxes.
05: */
06: public class MailSystem
07: {
08:    /**
09:       Constructs a mail system with a given number of mailboxes
10:       @param mailboxCount the number of mailboxes
11:    */
12:    public MailSystem(int mailboxCount)
13:    {
14:       mailboxes = new ArrayList();
15: 
16:       // Initialize mail boxes.
17: 
18:       for (int i = 0; i < mailboxCount; i++)
19:       {
20:          String passcode = "" + (i + 1);
21:          String greeting = "You have reached mailbox " + (i + 1)
22:             + ". \nPlease leave a message now.";
23:          mailboxes.add(new Mailbox(passcode, greeting));
24:       }
25:    }
26: 
27:    /**
28:       Locate a mailbox.
29:       @param ext the extension number
30:       @return the mailbox or null if not found
31:    */
32:    public Mailbox findMailbox(String ext)
33:    {
34:       int i = Integer.parseInt(ext);
35:       if (1 <= i && i <= mailboxes.size())
36:          return (Mailbox) mailboxes.get(i - 1);
37:       else return null;
38:    }
39: 
40:    private ArrayList mailboxes;
41: }