1 import java.util.ArrayList;
2
3 /**
4
5 */
6 public class MailSystem
7 {
8 /**
9
10 @param mailboxCount
11 */
12 public MailSystem(int mailboxCount)
13 {
14 mailboxes = new ArrayList<>();
15
16 //
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
29 @param ext
30 @return
31 */
32 public Mailbox findMailbox(String ext)
33 {
34 int i = Integer.parseInt(ext);
35 if (1 <= i && i <= mailboxes.size())
36 return mailboxes.get(i - 1);
37 else return null;
38 }
39
40 private ArrayList<Mailbox> mailboxes;
41 }