Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote