Create a class named FormLetterWriter that includes two overloaded methods named
ID: 640178 • Letter: C
Question
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, and it displays the salutation "Dear Mr. or Ms." followed by the last name. The second method accepts two Strings parameters that represents 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.
Explanation / Answer
public class FormLetterWriter {
public void displaySalution(String lName){
System.out.println("Dear Mr. " + lName);
System.out.println("Thank You for your recent order");
}
public void displaySalution(String fName, String lName){
System.out.println("Dear " + fName + " " + lName);
System.out.println("Thank You for your recent order");
}
public static void main(String args[]){
String fName = "David";
String lName = "Beckham";
FormLetterWriter letterWriter = new FormLetterWriter();
letterWriter.displaySalution(lName);
letterWriter.displaySalution(fName, lName);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.