Java Please Provide a class for authoring a simple letter. In the constructor, s
ID: 3758718 • Letter: J
Question
Java Please
Provide a class for authoring a simple letter. In the constructor, supply the names of the sender and the recipient Also supply a program Letter Printer that prints this letter. Dear John: I am sorry we must part. I wish you all the best Sincerely, Mary Construct an object of the letter class and call add Line twice. Hints: (1) use the con cat method to form a longer string from two shorter strings. (2) The special string n represents a new line. For example the statement body = body . con cat (sincerely ) con cat (n) Adds a line containing the string sincerely to the bodyExplanation / Answer
public class Letter{
private String from;
private String to;
private String body;
public Letter(){}
public Letter(String from,String to){
this.from = from;
this.to = to;
this.body = "";
}
public void addLine(String line){
body += line + " ";
}
public String getText(){
return body;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.