Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Description of the Program In this assignment, you will write four java files, Message.java, MessageTester.java, Mailbox.java and MailboxTester.java, Stage 1: In the first

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

1 Description of the Program In this assignment, you will write four java files, Message.java, MessageTester.java, Mailbox.java and MailboxTester.java, Stage 1: In the first file Message.java, create a class named Message that models an email message. It should contain the following: Private instance variables sender, recipient, and messagetext; A default constructor that takes no inputs (set all members to an empty string); A constructor takes all three inputs (sender, recipient and messagetext); Three getter methods to return each of three instance variables (accessor); Three setter methods to change each of three instance variables (mutator); A method toString that makes the message into one long string like this: From: Harry Morgan To: Rudolf Reindeer This is my message... Stage 2: In the second file MessageTester.java, write code to test the methods that you write in the class of Message.java. Specifically: 1. Create two message objects using the constructor taking inputs. The inputs are from ''messages0.txt'. You can either read the file into message objects, or you can manually initialize the objects using the information from the file. 2. Print them out using toString() method. 3. Set each object using setter methods (Inputs, e.g., Current Sender1, CurrentRecipient1). 4. Display each object's information using getter methods. Your output should look like Figure 1. 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: BlueJ: Terminal Window- 1 Solution Options After creating message objects: From: Original Sender 1 To: OriginalRecipient1 This is my original message1 From: OriginalSender2 To: OriginalRecipient2 This is my original message2 After using setter and getter methods: Sender: Current Sender1 Recipient: CurrentRecipient1 Message text: This is my current message1 Sender: Current Sender2 Recipient: CurrentRecipient2 Message text: This is my current message2 Can only enter input while your programming is running Figure 1: A screenshot of the program output 1. 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 messsages 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: Your 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. Bluel: Terminal Window - 1 Solution Options Message list in the mailbox after loading from a file Message 1 From: Eric_A_Bially To: Zachary_B_Howard This is_test_message_1 Message 2 From: Brett_V_Bohorquez To: Marcus_R_McPartland This is_test_message_2 Message 3 From: Aron_I_Brewster To: Patrick_C_Nauman This is_test_message_3 Message 4 From: Joshua_J_Dennis To: Jacob_G_Neff This is_test_message_4 Message 5 From: Stephen_M_Gentzler To: Kevin_A_Orlowski This_is_test_message_5 Message 6 From: Adam_James_D_Geosits To: Oscar_J_Phillips This is_test_message_6 Message 7 From: Rudolf_C_Gouker To: Andy_R_Sayer This_is_test_message_7 Message 8 From: Zachary_B_Howard To: Craig_Smith This is_test_message_8 Figure 2: A screenshot of the program output 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 print AllMessages () method. Your output should look like Figure 3. Bluel: Terminal Window-1,Solution Options Message list in the mailbox after removing six messages Message 1 From: Rudolf_C_Gouker To: Andy_R_Sayer This is_test_message_7 Message 2 From: Zachary_B_Howard To: Craig Smith This_is_test_message_8 Can only enter input while your programming is running Figure 3: A screenshot of the program output 3. 2 Required outputs You should print out all three outputs as shown in Figures 1-3. Put them together (copy and paste) in one output file (.txt).

Step by Step Solution

3.44 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

ANSWER Mailboxjava package mailbox class Message variables String sender String recipient String messagetext default constructor Message thissender th... 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_2

Step: 3

blur-text-image_3

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

Fundamental Managerial Accounting Concepts

Authors: Thomas Edmonds, Christopher Edmonds, Bor Yi Tsay, Philip Olds

8th edition

978-1259569197

More Books

Students also viewed these Programming questions