/** This class may be used to issue personalized greetings (character strings consisting of a greeting followed by a comma followed by a person's name The greeting to be used is hard coded into the method, while the name to be used is obtained interactively from the user. A different greeting is used on the first access to an object than on subsequent accesses. */ import java.util.Scanner; public class PersonalizedGreeter { // the name of the person to be greeted private String name; // the greeting to be used next private String nextGreeting; /** Constructs a PersonalizedGreeter for a user with a given name @param s the name */ public PersonalizedGreeter() { Scanner sc = new Scanner(System.in); System.out.print("What is your name? "); name = sc.next(); nextGreeting = "Welcome, "; sc.close(); } /** Greets the user for this PersonalizedGreeter by printing a String to the console The greeting for second and subsequent invocations of this method on an object acknowledges that the object has been accessed before by this method */ public void access() { System.out.print(nextGreeting); System.out.print(name); System.out.println("!"); nextGreeting = "Welcome back, "; } }