Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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.

image text in transcribed

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 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of Lucy Clifford ?

Answered: 1 week ago

Question

Prepare a short profile of Rosa parks?

Answered: 1 week ago

Question

Prepare a short profile of victor marie hugo ?

Answered: 1 week ago