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: 661870 • 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 accpets two String parameters that represent a first and last name, and it diplays 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.

Explanation / Answer

public class FormLetterWriter
   {
       private static final String SALUTATION1 = "Dear Mr. or Ms. ";
       private static final String SALUTATION2 = "Dear ";
       public String lastName;
       public String firstName;
       private static final String LETTER_END = "Thank you for your recent order";
       public void displaySalutation(String last)
           {
               lastName = last;
               System.out.println(SALUTATION1 + lastName);
           }
       public void displaySalutation(String last, String first)
           {
               lastName = last;
               firstName = first;
               System.out.println(SALUTATION2 + firstName + " " + lastName);
           }
       public void displayLetter()
           {
               System.out.println(LETTER_END);
           }
       public static void main(String[] args)
           {
               FormLetterWriter test001 = new FormLetterWriter();
               FormLetterWriter test002 = new FormLetterWriter();
               test001.displaySalutation("Henry");
               test001.displayLetter();
               test002.displaySalutation("Henry", "Kimberly");
               test002.displayLetter();
           }
   }

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