Question
Stage 3: In the third file Mailbox.java, create a class named Mailbox that models a mailbox that contains a list of email messages. It should
Stage 3: In the third file Mailbox.java, create a class named Mailbox that models a mailbox that contains a list of email messages. It should contain the following:
Private instance variables messages and numOfMessages
Hint: the type for messages should be ArrayList
public Mailbox() A default constructor to initialize two instance variables
public void addMessage(Message m) Add a new message into the list messages, and update the numOfMessages
public Message getMessage(int i) Return the ith message from the list
public int getNumberOfMessages() Return the number of messages in mailbox
public void removeMessage(int i) Remove the ith message from the list
public void printAllMessages() Print out all messages in the mailbox
Stage 4: In the fourth file MailboxTester.java, you will need to do the followings:
1. Create an object of Mailbox type.
2. Read all eight messages into Mailbox object from the file of messages1.txt. The values for each line will be used to initialize each instance variable of the Message object, and then added into the Mailbox object. Important: You must read the values in from the file using Scanner object, you are not allowed to initialize the objects manually.
3. Print out all messages using printAllMessages() method. Your output should look like Figure 2
4. Remove message at position 0 (index) using removeMessage(), and repeat it six times.
5. Print out all messages in the mailbox object using printAllMessages() method.
Your output should look like Figure 3.
Optbiars Message, list in the mailbox #fter loading from file Hessage 1 From: Eric A Dially o: achary_B_Howard This is test nessage 1 Mesaage 2 From: Brett V Bohorque:z To: Narcus R_HcPartland Ih18 1s_test_nessage_2 Message 3 rom: Aron_I_Brewster To: Patrick C Nauman This 1s_test nessage 3 Message 4 Fram: Joshua-J_Dennis To: Jacob_G_Neff This is test nessage 4 Hessage5 From: Stephen N Gentzler To: Kevin A_Orlowski Th1a_is_test neasage 5 Message 6 rom: Adam_ Janes D Geosits To: Oscar J_Phillips Th1s 1s-test nessage.6 Message 7 Fram: Rudolf C_Gouker To: Andy_R_Sayer Thisis_test nessage 7 Mesaage8 From: Zachary B_Howard To: Cra19 Smith This_is_test nessage 8Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started