Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class Mailbox that stores e-mail messages, using the Message class of P

ID: 3670900 • Letter: D

Question

Design a class Mailbox that stores e-mail messages, using the Message class of Part 1. Implement the following methods in addition to an appropriate constructor:

1. public void addMessage(Message m)

2. public Message getMessage(int i)

3. public void removeMessage(int i)

In addition, each individual mailbox (object instance) must have a constant string that represents the signature. This signature must be appended to the end of each message after it is added to the mailbox.

(the following is what i have done for Message Class)

public class Message {
private String sender;
private String recipient;
private String body = "";
public static final String from = "From: ";
public static final String to = " To: ";

public Message(String sender, String recipient) {

this.sender = sender;
this.recipient = recipient;
}

public void append(String words) {
this.body += words + " ";
}

public String toString() {
return from + sender + to + recipient + " " + body + " ";
}
}

I need the mailbox class

Explanation / Answer

import java.util.ArrayList;

import java.util.Scanner;

public class MessageTest

{

Public static void main(String args[])

    {

//creating objects for MessageTest class

   MessageTest m1=new Message("professor1", "class"));

   m1.append("Today discussing topic");

MailBox mb=new MailBox();

mb1.addMessage(m1);

MessageTest m2=new Message("professor2", "class2"));

         m1.append("Today assignment is");

mb1.addMessage(m2);

System.out.println(mb1.getmessage(0));

System.out.println(mb1.getmessage(1));

}

public class MailBox

{

//since mails are personal

private ArrayList<message> emailmsg=new ArrayList<message>();

//default constructor

public MailBox()

{

emailmsg=new ArrayList<message>();

}

//adding messages to mailbox

public void addMessage(Message m)

{

emailmsg.add(m);

}

public Message getMessage(int i)

{

return emailmsg.add(i);

}

public void removeMessage(int i)

{

emailmsg.remove(i);

}

}

//For each individual mailbox have a constant string that represents the signature

//Message a static class run automatically

public static class Message

{

private String sender;

private String recipient;

private String Message;

public Message(String s,String r)

{

sender=s;

recipient=r;

}

public void append(string m)

{

message=m;

}

Public void setMessage()

{

Scanner input=new Scanner(System.in);

System.out.println("message is");

message=input.nextLine();

}

Public String toString()

{

return "Sender name"+sender+"/n"+" recipient name"+ recipient +"/n"+"Message is"+ message+"/n");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote