CSCI 201

Fall 2001

Assignment 2


  1. Write a program called NameCheck that starts by prompting the user to enter his or her first name. Then check that name for the following properties, in the order given below. In each case, make the appropriate response as indicated:

    1. If the "name" does not start with an uppercase letter, the program should reply with the message "That doesn't look like a proper name!" and stop immediately.

      Hint: Note that the individual characters in a String object are numbered or indexed, with the first character at index 0 (not 1). In this context, you may want to check out the String instance method charAt() on p. 75. ... And finally, you may want to meditate on the meaning of the following boolean expression, in which c is a char variable:

                                (c >= 'A' && c <= 'Z')
          
    2. If the name contains less than 4 letters, the program should write the output line "That's a short name...", and then proceed to make the remaining checks.
    3. If the name contains more than 10 letters, the program should write the output line "That's a long name..." and proceed.
    4. If your program reaches this point, it should now write two final output lines similar to the ones shown below (where the name is assumed to be "Alice"):

          So you say your name is "Alice". Well, nice to meet you, Alice!
          Gotta go, bye now!
          

  2. Implement Programming Project 3.7 in your text (p. 170). Name the java file containing your program HiLo.


Submitting Programs

Both programs written for this assignment must be turned in by transferring the respective java source code files to your ftp directory for this class. For each program, only the source code file (i.e., NameCheck.java, and HiLo.java) should be turned in and the files must have exactly those names. You were shown how to transfer files to your class ftp directory in lab 1, here is a quick refresher.