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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

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. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,