Post a New Question

java programming

posted by .

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
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

Student name

  • java programming -

    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";
    String line2 =" ";
    String line3=" Student of java class";
    // System.out.println(line3);
    String line4="question";
    // System.out.println(line4);
    String line5="sincerely";
    String 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;

    String ns ="Sincerely ,";
    String line6=" ";

    String student = "b";
    String a =ns +"\n" + student;

    public static void main(String[] args)




  • java programming -

    Here are some java programming tutorials that I hope will help you and don't forget the Related Questions down below:


  • java programming -

    What does happen?

Answer This Question

First Name:
School Subject:

Related Questions

More Related Questions

Post a New Question