import java.util.Scanner; /** This class creates a greeter with its own greeting that can be further tailored to greet a user by name. @author Jeff Smith */ public class PersonalizableGreeter { // the greeting to be used by the greet method private String greeting; /** Constructs a PersonalizableGreeter object with a given greeting @param g the greeting */ public PersonalizableGreeter(String g) { greeting = g; } /** Prints a greeting tailored to a user, given the user's name as read in from the console. */ // The scanner is not closed, since this will // crash in Eclipse -- closing a scanner // may close the input source public void greet() { Scanner sc = new Scanner(System.in); System.out.println("What is your name?"); String userName = sc.nextLine(); System.out.println( greeting + ", " + userName + "!"); } }