The above Message class can be used as a simple object to construct an e-mail me
ID: 3690402 • Letter: T
Question
The above Message class can be used as a simple object to construct an e-mail message. The to and from e-mail addresses are set by the constructor, and the message is assembled one string at a time using the append method. Using the above Message class, write a simple main method that prompts the user for a source, a destination, and lines of their message, using the methods of the Message class to construct an e-mail message object. When the user enters an empty line for the message body, the program should use the displayMessage() method to display the finished e-mail message to the console and then end.
1 public class Message f private String msg; private String to; private String from; * Constructs a new Message object from a source to *a destination * param source the "From" source of the message * param dest the "To" destination of the message 18 12 13 14 15 16 17 18 19 28 21 public Message(String source, String dest) f this.from = source; this.to = dest; this.msg = ... ; * Returns the source of the message * return the message source public String getFrom() 23 24 25 26 27 return this.from; * Returns the destination of the message * return the message destination 29 39 31 32 public String getTo) f return this.to; 35 * Adds a line to the end of the message * @param the line to add 37 38 39 48 public void append (String msg) this.msg this.msg + msg; 42 43 * Returns the current text of the message * return the current text 45 47 public String getMessage() 1 return this.msg.; 49 50 51 52 53 * Displays the current message to standard output public void displayMessage) 56 57 58 59 60 61 System.out.println("To: " + this.to); System.out.println("From: " + this.from); System.out.println("-- System.out.println(this.msg);Explanation / Answer
I have written the main code for the class. working code:
public static void main (String[] args) {
Message m= new Message("abc@ca.com","ahas@as.com");
m.getFrom();
m.getTo();
m.append("hi this is my message")l
m.getMessage();
m.display();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.