Asked by JJ
Provide a class called Letter for authoring a simple letter. The letter class has three data fields, the name of the sender, the name of the recipient, a body of the letter.
1. Supply the class constructors (default , and overloaded )
2. Supply a method.
Public void addLine (String Line)
To add a line of text to the body of the letter
The addLine method should through an exception if the line is empty.
3. Supply a method.
Public String getText()
That returns the entire text of the letter.The text has the form :
Dear recipient name:
Blank Line
First line of the body
Second line of the body
…
Last line of the body
Blank line
Sincerely,
Blank line
Sender name
4. Also supply a program LetterPrinter that asks the user to enter lines of text nd verifies that the lines are not empty and prints the following letter :
Dear teacher:
Line supplied by the user
Line supplied by the user
Sincerely,
Student name
1. Supply the class constructors (default , and overloaded )
2. Supply a method.
Public void addLine (String Line)
To add a line of text to the body of the letter
The addLine method should through an exception if the line is empty.
3. Supply a method.
Public String getText()
That returns the entire text of the letter.The text has the form :
Dear recipient name:
Blank Line
First line of the body
Second line of the body
…
Last line of the body
Blank line
Sincerely,
Blank line
Sender name
4. Also supply a program LetterPrinter that asks the user to enter lines of text nd verifies that the lines are not empty and prints the following letter :
Dear teacher:
Line supplied by the user
Line supplied by the user
Sincerely,
Student name
Answers
Answered by
JJ
This is the code what i tried but its not thw thing i want
import javax.swing.*;
public class Letter
{
private String sendername;
private String recipientname;
private String bodyletter;
public static void sender (String nsender)
{
String name= "a";
}
public static void recipient (String nrecipient)
{
String name= "b";
}
public static void letter (String bletter)
{
String letter="Studentletter";
}
public static void addLine (String line)
{
String linea=" ";
}
public String getText()
{
String body= "Dear natasha";
//System.out.println(body);
String line2 =" ";
//System.out.println(line2);
String line3=" Student of java class";
// System.out.println(line3);
String line4="question";
// System.out.println(line4);
String line5="sincerely";
//System.out.println(line5);
String line6=" ";
//System.out.println(line6);
String line7="john";
// System.out.println(line7);
String n =body+ "\n "+ line2 + "\n" + line3 + "\n" + line4 + "\n" + line5 + "\n" + line6 + "\n" + line7;
//return n ;
return getText();
}
public static void letterPrinter()
{
String s1="Dear Teacher !";
String user="I am a student of class java.";
String s= s1 + "\n" + user;
System.out.println(s);
String ns ="Sincerely ,";
String line6=" ";
System.out.println(line6);
String student = "b";
String a =ns +"\n" + student;
System.out.println(a);
}
public static void main(String[] args)
{
letterPrinter();
}
}
import javax.swing.*;
public class Letter
{
private String sendername;
private String recipientname;
private String bodyletter;
public static void sender (String nsender)
{
String name= "a";
}
public static void recipient (String nrecipient)
{
String name= "b";
}
public static void letter (String bletter)
{
String letter="Studentletter";
}
public static void addLine (String line)
{
String linea=" ";
}
public String getText()
{
String body= "Dear natasha";
//System.out.println(body);
String line2 =" ";
//System.out.println(line2);
String line3=" Student of java class";
// System.out.println(line3);
String line4="question";
// System.out.println(line4);
String line5="sincerely";
//System.out.println(line5);
String line6=" ";
//System.out.println(line6);
String line7="john";
// System.out.println(line7);
String n =body+ "\n "+ line2 + "\n" + line3 + "\n" + line4 + "\n" + line5 + "\n" + line6 + "\n" + line7;
//return n ;
return getText();
}
public static void letterPrinter()
{
String s1="Dear Teacher !";
String user="I am a student of class java.";
String s= s1 + "\n" + user;
System.out.println(s);
String ns ="Sincerely ,";
String line6=" ";
System.out.println(line6);
String student = "b";
String a =ns +"\n" + student;
System.out.println(a);
}
public static void main(String[] args)
{
letterPrinter();
}
}
Answered by
MattsRiceBowl
What does happen?
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.