Computer Science 221: Software Design Lab

Fall 2005

Professor McCracken

 (Slightly modified 9.9.2005)

 (\Further slightly modified 9.14.2005)

 

Section P (Tuesday and Thursday) Beginning of class Thursday, September 22.

Section G (Monday and Wednesday) Beginning of class Wednesday, September 21.

 

Homework 2 (both sections). A completed program is due at the beginning of class on dates shown.

This homework will be done in the same teams of two as in HW1.

Modify your HW1 solution to do the following additional things:

 

  1. Add labels and textfields for ten seven additional items: phone number, street address, city, and state, and three groups of digits of the Social Security Number. Error checking should be done using regular expressions wherever possible.
    1. The phone number must be ten digits, and may be in either the 2223334444 form, or 222-333-4444. You need not give instructions; most people will do the second form, I think. Accept either, without comment. Reject any entry has any non-numeric character except the hyphen. Further, the first digit in the first group (222) cannot be zero or one, and first digit in the second group (333) cannot be zero.
    2. The city may be from one to four words; the state must be one or two words. (There is no need to check whether the state supplied really exists.) (There is at least one four-word city name: North Salt Lake City, Utah.)
    3. Read the street address as a string (just like the others) and do no error checking on it.
    4. Provide three smaller textboxes for the digits of the Social Security Number. Set up your program so that after the user types three digits into the first box, the cursor moves to the second box; after the user types two digits into the second box, the cursor moves to the third box. This will require action listeners. Try to put these three boxes on one line.
    5. ADDED 9.14.2005: Make sure that the Social Security number has correct format: three digits, then two digits, then four digits.
  2. Add a Submit button. When pressed, your program reads the data from the ten text fields, doing the required checking on each. Errors still go to the console. When all are correct, print “Thank you.” NOTE: this does mean that the user may hit Enter after each field or not. Your program should react correctly either way. And, either way, don’t report errors until the user clicks on Submit.
  3. If there are errors, provide helpful but brief notifications. Do NOT remove the erroneous entry, but change the text entry to red. When correct data is entered, change back to black.
  4. The individual fields should NOT have action listeners, except for the first two tetxtboxes of the Social Security Number. Oops! I just changed that. They all need action listeners. This is going to get repetitive. Perhaps we’ll figure out some way (later in the semester) to build a “factory” that builds such code.  Process everything in response to a click of the Submit button. Then print the information in the appropriate choice shown in these examples.

 

Daniel D. McCracken

123-45-6789

160 Cabrini Blvd. Apt. 136

North Salt Lake City, Utah 84054

212-568-6432

 

or

 

Daniel McCracken

123-45-6789

 160 Cabrini Blvd. Apt. 136

Saint Louis Obispo, CA 93401

2125685381

 

Note that you supply the period after the middle initial, and that if the user does not enter a middle initial there should not be any blanks where that would have been. Note also that you do no error checking on the city and state. (“Saint Louis” in the sample output should be “San Luis.”)

The presence of the middle initial is still optional. If present, print it as a capital letter, regardless of how the user entered it. The method toUpperCase can be applied to a string.

The checking of the ZIP code, the telephone number, the city, and the state should all be done using regular expressions and the Java match method. Regular expressions are very powerful; everybody using a computer at your level has to know them. See page pp 1378ff in the sixth edition and pp 543ff in the fifth edition. (Checking the street address would be horribly complicated; don’t touch that. There are a gadzillion legitimate variations.) Make sure that all characters in the Social Security Number are digits.

Feel very free to use Refactor/Rename to improve the understandability of variable names.

But please do not get excited about the exact format of the output. If this were a course in website usability, we’d worry about a lot of things. But we’d also have the knowledge of how to use layout managers, etc. Let’s learn what we can by finishing this assignment, and move on to other things. There is so much interesting and useful stuff to choose from, and only 14 weeks in the semester!

 Back to Dan McCracken's  Home Page