    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 mail boxes
    10:       @param mailboxCount the number of mailboxes
    11:    */
    12:    public MailSystem(int mailboxCount)
    13:    {
    14:       mailboxes = new ArrayList<Mailbox>(mailboxCount);
    15:
    16:       /*
    17:          Initialize mail boxes.
    18:       */
    19:       for (int i = 0; i < mailboxCount; i++)
    20:       {
    21:          String passcode = "" + (i + 1);
    22:          String greeting = "You have reached mailbox " + (i + 1)
    23:             + ". \nPlease leave a message now.";
    24:          mailboxes.add(i, new Mailbox(passcode, greeting));
    25:       }
    26:    }
    27:
    28:    /**
    29:       Locate a mailbox.
    30:       @param ext the extension number
    31:       @return the mailbox or null if not found
    32:    */
    33:    public Mailbox findMailbox(String ext)
    34:    {
    35:       int i = Integer.parseInt(ext);
    36:       if (1 <= i && i <= mailboxes.size())
    37:          return  mailboxes.get(i - 1);
    38:       else return null;
    39:    }
    40:
    41:    private ArrayList<Mailbox> mailboxes;
    42: }