229k views
4 votes
Create a class named FormLetterWriter that includes two overloaded methods named displaySalutation(). The first method takes one String parameter that represents a customer's last name, it displays the salutation "Dear Mr. or Ms." followed by the last name. The second method accepts two String parameters that represent a first and last name, and it displays the greeting "Dear" followed by the first name, a space, and the last name. After each salutation, display the rest of a short business letter: "Thank you for your recent order." Write a main() method that tests each overloaded method. Save the file as FormLetterWriter.java.

User Jason Chen
by
4.7k points

1 Answer

2 votes

Answer:

Follows are the code to this question:

public class FormLetterWriter//defining class

{

static void displaySalutation(String last_Name)//defining a method displaySalutation

{

System.out.println("Dear Mr. or Ms. " + last_Name);//print value

}

static void displaySalutation(String first_Name, String last_Name) //overload the method displaySalutation

{

System.out.println("Dear " + first_Name + " " + last_Name);//print value

}

public static void message()//defining a method message

{

System.out.println("Thank you for your recent order.");//print message

}

public static void main(String[] args) //defining main method

{

displaySalutation("I Kell");//calling a method displaySalutation by passing a single String value

message();//calling message method

displaySalutation("Christ", "John");//calling a method displaySalutation by passing a two String value

message();//calling message method

}

}

Output:

please find the attached file.

Step-by-step explanation:

In the above given program a calss "FormLetterWriter" is defined, in side the class we perform the method overloading, in which a method "displaySalutation" is used in first definition it accepts a single string variable "first_Name", and in second time, it accept two string variable " first_Name and last_Name".

Inside the both method, we use print method, that print its value, and an onther method message is defined, that print the given message.

In the class main method is declared, in which we apply mathod overloading and also call the message method for print the given business letter.

Create a class named FormLetterWriter that includes two overloaded methods named displaySalutation-example-1
User Kakoma
by
4.4k points