Using JAVA Part A) Design a class Message that models an e-mail message. A message has a recipient, a sender, and a message text. Support the following methods: 1) A constructor that takes the sender and recipient. 2) A method append that appends a line of text to the message body A method toString that makes the message into one long string like: “From: Harry Morgan%nTo: Rudolf Reindee%n . . . “ Write a program that uses this class to make a message and print it. Part B) Design a class Mailbox that stores e-mail messages, using the Message class in part a) Implement the following methods in the Message class. public void addMessage(Message m) // Adds Message M to the Mailbox public Message getMessage(int i) // returns the ith message from the Mailbox public void removeMessage(int i) // removes the ith message from the Mailbox public int mailBoxSize () // returns the number of messages in the Mailbox Write a program to demonstrate the functionality of the Mailbox. Add messages to the Mailbox, print messages from the Mailbox, then remove a message form the Mailbox.
Using JAVA
Part A) Design a class Message that models an e-mail message. A message has a recipient, a sender, and a message text. Support the following methods:
1) A constructor that takes the sender and recipient.
2) A method append that appends a line of text to the message body
- A method toString that makes the message into one long string like: “From: Harry Morgan%nTo: Rudolf Reindee%n . . . “
Write a program that uses this class to make a message and print it.
Part B) Design a class Mailbox that stores e-mail messages, using the Message class in part a) Implement the following methods in the Message class.
- public void addMessage(Message m) // Adds Message M to the Mailbox
- public Message getMessage(int i) // returns the ith message from the Mailbox
- public void removeMessage(int i) // removes the ith message from the Mailbox
- public int mailBoxSize () // returns the number of messages in the Mailbox
Write a program to demonstrate the functionality of the Mailbox. Add messages to the Mailbox, print messages from the Mailbox, then remove a message form the Mailbox.
The JAVA code is given below with output screenshot
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
I am recieving error "void cannot be dereferenced" and therefore "cannot envoke toString()"
How would one fix this?
System.out.println(mailbox.getMessage(0).toString());
System.out.println(mailbox.getMessage(1).toString());