/** This class prints a friendly welcome message. */

public class Hello {

    /** Prints a welcome message. The user must specify his or her name on
     * the command line.
     *
     * @param args the command-line arguments. Should contain at least one
     *             argument, the name of the user.
     * @throws NoNameException if the user does not enter a name.
     * @see #getName
     */
    public static void main( String[] args ) throws NoNameException {
        String name = getName( args );
        System.out.println( "Hello, " + name + "!" );
    }



    /** Extracts the user's name from the input arguments.
     * Precondition: <code>args</code> should contain at least one element,
     * the user's name.
     *
     * @param args the command-line arguments. 
     * @return the user's name (the first command-line argument).
     * @throws NoNameException if <code>args</code> contains no element.
     */
    public static String getName( String[] args ) throws NoNameException {
        if( args.length == 0 ) {
            throw new NoNameException();
        } else {
            return args[0];
        }
    }
}
