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

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

}

}

What does happen?

Here is the implementation of the "Letter" class in Java:

```java
public class Letter {
private String senderName;
private String recipientName;
private StringBuilder body;

// Default constructor
public Letter() {
this.senderName = "";
this.recipientName = "";
this.body = new StringBuilder();
}

// Overloaded constructor
public Letter(String senderName, String recipientName) throws Exception {
if (senderName.isEmpty() || recipientName.isEmpty()) {
throw new Exception("Sender and recipient names cannot be empty");
}
this.senderName = senderName;
this.recipientName = recipientName;
this.body = new StringBuilder();
}

public void addLine(String line) throws Exception {
if (line.isEmpty()) {
throw new Exception("Line cannot be empty");
}
body.append(line).append("\n");
}

public String getText() {
StringBuilder letterText = new StringBuilder();
letterText.append("Dear ").append(recipientName).append(":\n\n");
letterText.append(body);
letterText.append("\nSincerely,\n\n");
letterText.append(senderName);
return letterText.toString();
}
}
```

And here is the implementation of the "LetterPrinter" program:

```java
import java.util.Scanner;

public class LetterPrinter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter sender name: ");
String senderName = scanner.nextLine();

System.out.print("Enter recipient name: ");
String recipientName = scanner.nextLine();

Letter letter;
try {
letter = new Letter(senderName, recipientName);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
return;
}

System.out.println("\nEnter lines of text:");
while (true) {
String line = scanner.nextLine();
if (line.isEmpty()) {
break;
}
try {
letter.addLine(line);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}

scanner.close();

System.out.println("\nLetter:");
System.out.println(letter.getText());
}
}
```

With this, you can create a Letter object, add lines to its body, and print the complete letter based on the input provided by the user in the LetterPrinter program.

Here is the implementation of the requested class "Letter" and the program "LetterPrinter":

```java
import java.util.ArrayList;

public class Letter {
private String senderName;
private String recipientName;
private ArrayList<String> body;

public Letter() {
this.senderName = "";
this.recipientName = "";
this.body = new ArrayList<>();
}

public Letter(String senderName, String recipientName) {
this.senderName = senderName;
this.recipientName = recipientName;
this.body = new ArrayList<>();
}

public void addLine(String line) throws IllegalArgumentException {
if (line.isEmpty()) {
throw new IllegalArgumentException("Line cannot be empty.");
}
body.add(line);
}

public String getText() {
StringBuilder text = new StringBuilder();
text.append("Dear ").append(recipientName).append(":\n");
text.append("\n");
for (String line : body) {
text.append(line).append("\n");
}
text.append("\n");
text.append("Sincerely,\n");
text.append("\n");
text.append(senderName);
return text.toString();
}
}
```

And here is the implementation of the program "LetterPrinter":

```java
import java.util.Scanner;

public class LetterPrinter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter your name: ");
String senderName = scanner.nextLine();

System.out.print("Enter recipient's name: ");
String recipientName = scanner.nextLine();

Letter letter = new Letter(senderName, recipientName);

System.out.println("Enter lines of text for the letter (press Enter to finish):");

boolean isValid = true;
do {
String line = scanner.nextLine();
try {
letter.addLine(line);
} catch (IllegalArgumentException e) {
System.out.println("Invalid input: " + e.getMessage());
isValid = false;
}
} while (isValid);

System.out.println("Printing the letter:\n");
System.out.println(letter.getText());
}
}
```

To use this code, you can create a new Java project and add the above code into the respective classes. Then, run the `LetterPrinter` program. It will prompt you to enter your name, recipient's name, and lines of text for the letter. After that, it will print the formatted letter on the console.