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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter1: Creating Java Programs
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

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.

  1. public void addMessage(Message m) // Adds Message M to the Mailbox
  2. public Message getMessage(int i) // returns the ith message from the Mailbox
  3. public void removeMessage(int i) // removes the ith message from the Mailbox
  4. 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.

Expert Solution
Step 1

The JAVA code is given below with output screenshot

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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());

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Software Development
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning