Assignment # 6

Threading some Exceptional Strings

Due: Wednesday, November 11th by midnight.

Deliverables: Email all files that you create to cis3931@cs.fsu.edu by the due date, including a journal/diary of the steps you went through during this assignment. Since many of the assignments involve writing Java applets it will greatly assist the grading of the assignments if you create HTML on your home page that includes the assignment's applets. Please include the web address of your applet in the journal/diary. Note that for assignments that require you to create source code yourself rather than type in existing code (like this one) you should take careful measures not to accidentally make your .java files world-readable within your HTML directory.

When emailing your files it can be problematic to faithfully re-create the file names. Here are detailed instructions that you can use for this and future assignments. If you use xi.cs.fsu.edu (which is running Solaris) you can create a single compress "tar" file that can then be emailed to cis3931@cs.fsu.edu.

cd location_of_P6_source
gnutar czvf ~/P6.tar.gz .

If you use an email client that supports attachments then you can just attach the file P6.tar.gz to your email submission. If you do not use an email client that supports attachments you will first have to convert the binary compressed "tar" file into a format suitable for an email message, such as uuencoding. Here is an example of encoding the P6.tar.gz file and sending it via a UNIX pipe to a mail client:

uuencode P6.tar.gz < P6.tar.gz | /usr/ucb/mail -s "P6.tar.gz" cis3931@cs.fsu.edu

If you choose to use some other operating system, such as Windows '95, Windows NT or Windows '98 be careful that you use a compression agent that correctly preserves both case sensitivity and the entire file name length, such as WinZip.

You will be asked to re-submit your assignment via email if the format you use is not correctly identified and/or formatted. Please do not email all the files separately.

Assignment:

This assignment covers materials in Lesson 12 (Using String and StringBuffer), Lesson 15 (Handling Errors with Exceptions) and Lesson 16 (Doing Two or More Tasks at Once: Threads) as well as using some of the AWT components you learned from the previous assignment.

You are to write, from scratch, a Java applet that performs the following tasks. Here is the reference applet that you can use to see how it looks and operates.

  1. Lays out five TextFields and two TextAreas so that the labels and the text fields are arranged as given in the example applet.
  2. The first TextField accepts input from the user; the remaining AWT components are all non-editable and will be used to display various strings. The input string from the user is validated according to the rules specified later.
  3. The second TextField will display an accepted input string in reverse order (reversed by letters).
  4. The third TextField will display the input string in reverse word order.
  5. The fourth TextField will display the input string in random word order.
  6. The fifth TextField will display the input string in Pig Latin. The rules for Pig Latin are:
    1. For each word, find the first consonants before a vowel appears (a vowel is considered to be either a, e, i, o, u or y).
    2. Print out the rest of the word starting with the first found vowel.
    3. Print out any consonants found at the first step.
    4. Print out the string "ay".
    5. Examples: "dog" in Pig Latin is spelled "ogday", "any" is "anyay" and "fleas" is "easflay".
  7. The first TextArea will display any exceptions that are thrown by your input string validator in a "log style" (as with the AWT component log in assignment # 5).
  8. The second TextArea will display the current list of all ThreadGroups and the Thread names within each group, with a one second pause between refreshes.

The input string must be validated before the string is plotted in the remaining four TextFields using the appropriate word mangling technique (reverse by letters, reverse by words, random by words and Pig Latin). A string is a valid sentence if:

  1. It is composed of only letters and spaces, except for the last position, which must contain a period (".").
  2. The first letter of the string is capitalized.

If the first letter is not capitalized, throw and catch an exception named "FirstLetterNotCapitalizedException". If the last character is not a period, throw and catch an exception named "SentenceNotPeriodTerminatedException". If the sentence contains any non-letter characters, throw and catch "IllegalCharactersException". If any exceptions are thrown, print an appropriate message to the log window (the first TextArea).

If the sentence passes all the tests, create a Thread for each of the four sentence-mangling methods. Each thread will display the result one character at a time with a .5 second pause between each character. For each sentence that is replotted, the first character must be capitalized, all remaining letters in the sentence must be lower case and the sentence must end in a period.