Assignment 01

Swedish Chef

This assignment is to be done individually. Hand it in electronically (using submit) before 4:00pm on Monday, September 25, 2006. For instructions, click here.

Important Note: Late assignments will not be accepted!

Download the starter files for Assignment 1 which includes all the files you need for this assignment.



For this assignment, you will accept words from the keyboard and output the text as though spoken by the Swedish Chef from the Muppets.

For our purposes, a word is a sequence of characters that is surrounded by whitespace (spaces, returns, etc.). Note that a word does not include any punctuation at the end - this is dealt with in the translation rules. Unless noted in the rules, you do not have to deal with capital letters.

To transform a word from English to Swedish Chef, use the following rules (and note any hints or dependencies mentioned):

  1. If the word is "END" (case-sensitive) then do not translate the word and stop accepting input. This ends your program.
    NOTE: Be sure you do this first, as it is difficult to stop a DrJava program that is caught in an infinite loop with keyboard input.

  2. If the word ends with a comma or a period, remove it before applying any further rules. When you finish applying the rules, add the comma or period back. You can assume that there is only one punctuation symbol at the end of any given word, and none in the middle of a word. Do not worry about other punctuation symbols (exclamation marks, question marks, etc.).

  3. Replace any occurrence of the string "the" in a word with "zee". Also replace "The" with "Zee". That is, "them" becomes "zeem", and "ether" becomes "ezeer".

  4. If the word ends with the letters "th", replace "th" with "t".

  5. Replace any occurrence of the string "ow" with "uh", and "Ow" with "Uh".

  6. Replace any occurrence of the string "v" with "f", and "V" with "F".

  7. Replace any occurrence of the string "w" with "v", and "W" with "V".
    NOTE: This rule must be applied after Rule 5.

  8. Replace any occurrence of the string "an" with "un", and "An" with "Un".

  9. Replace any occurrence of the string "tion" with "shun".

  10. If a word ends with the letter "e", add "-a" to the end of the word.

  11. The first occurrence of the letter "i" that is completely contained in the word should be replaced with "ee". Or, if you prefer, the first occurrence of "i" that is not the first letter in the word should be replaced with "ee". For example, "initial" becomes "ineetial" (the first and third "i" are left alone) but "abiding" becomes "abeeding".
    NOTE: This rule must be applied after Rules 9 and 10. For Rule 10, that means "alumni" becomes "alumnee".

  12. If a word starts with "o", replace that "o" with "oo". Any other occurrence of "o" should be replaced with "u". If a word starts with "O", replace that "O" with "Oo".
    NOTE: This rule must be applied after Rules 5 and 9.

  13. At the end of every sentence or at the end of input (when the user types "END"), add a newline.

  14. At the end of every third sentence (that is, every third word that ends with a period), print "Bork bork bork!" as the next sentence before processing any more input.

To help you with the interpretation of the rules, we have provided a Java applet that provides a sample translator implementing these rules. Your output should match the output produced by the applet. The applet can be launched by pressing the button on this page.

Note that you can implement this assignment using the String class, getting substrings and appending strings together. Another option is to use the StringBuffer class, which includes string manipulation methods that you may find useful. A third option is regular expressions, which can make this assignment easier if you already understand them. Be warned that you should only use regular expressions if you are already familiar with them since you may receive limited tutor and TA help. You can look on the Resources page for a link to Java documentation to get more details on some of the classes for the alternate implementations.

Your assignment should follow the style and documentation guidelines laid out in class and on the CS 133 web site.

A very important consideration in this assignment is testing. You will need to construct test cases that check each rule in isolation and also check for combinations of rules to be sure that you're applying all of the necessary rules at all matching places in a word and in the correct order. The latter test cases will require some planning.


Electronic Submission

Programming assignments must be submitted electronically. Be sure to include your name and ID number in every file you submit.

Submit the following files:

Checking Submission

There is a utility on this page to see what files you have submitted for an assignment. It is always a good idea to check that you have submitted everything. Click here to check your submissions.