Assignment 3, CS 46A
30 points
due September 24, 2003

Define a class A3Greeter with a one-argument constructor and four other methods, as described below.

The constructor is to take a String argument representing the user's name.

There should be a void method greet, with no parameters, that greets the user by name. The greeting should include a basic greeting which is independent of the user's name, together with the user's name. You may include additional punctuation if you want, to get a greeting like

Howdy, Leo!

There should be a void method greetByNickname, with no parameters, that greets the user by nickname. The greeting should include the same basic greeting as for greet, but incorporate the user's nickname rather than their name.

There should be a void method buildNickname, with an int parameter, that builds and stores a nickname. This nickname is to be built from the user name simply by getting the prefix of that name consisting of the given number of characters. You needn't worry about the possiblility that the argument provided is larger than the length of the user's name.

Finally, there should be a void method shoutGreeting, with no parameters, that greets the user by name (as opposed to nickname), with all letters in upper case.

All greetings should be performed by simply sending one or more appropriate strings to System.out. You may use a basic greeting of your choice. Note that since there is a possibility that a greeting by nickname may be requested before the nickname has been built, you should make sure that a default value is available for the nickname. This value may also be a value of your choice.

For this assignment, you should provide a copy of your code on diskette or CD (no email), and a hard copy of your code. You needn't provide a hard copy of the results of your testing. However you should test your class definitions on your own with the code in the file A3.java, which is available on the class web site.

Please obey the following rules for documentation:

Use the javadoc style (with delimiters /** and */) for public instance fields and methods. For each parameter, use the @param format, with the name of the parameter and a description of its purpose immediately following @param. Note that there are no return values for any of the methods.

Use the double-slash comment format for private instance fields and methods.