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...


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., CurrentSender1, 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: 1 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 i th message from the list • public int getNumberOfMessages() Return the number of messsages in mailbox • public void removeMessage(int i) Remove the i th 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 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. Figure 2: A screenshot of the program output 2. 4. Remove message at position 0 (index) using removeMessage(), and repeat it six times. 3 5. Print out all messages in the mailbox object using printAllMessages() method. Your output should look like Figure 3. Figure 3: A screenshot of the program output 3.

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here