Skip Site NavigationCarleton College: Home
 
 

This assignment is to be done with your teammate (if you have one).

Overview

An important and common use for computer science ideas is for translating or converting text from one form, or one language, to another. Tools like Babel Fish will convert text from one language to another. Compilers convert computer programs from one programming language to another. For this assignment, you'll create a computer translator that will take text and convert it to pirate-speak. You'll be ready to go for International Talk Like A Pirate Day!

Specifics

Your mission is to create a program to convert English to Pirate. Create a directory called pirate for your code, and name your program Pirate.java. Specifically, here are some rules to follow:

  1. Replace words as follows. hello -> ahoy; hi -> yo-ho-ho; my -> me; friend -> bucko; sir -> matey; miss -> proud beauty; stranger -> scurvy dog; officer -> foul blaggart; where -> whar; is -> be; the ->th'; you -> ye; old -> barnacle covered; happy -> grog-filled; nearby -> broadside; restroom -> head; restaurant -> galley; hotel -> fleabag inn. Feel free to add more if you like, but embellish this later: this is the easy part. You might want to get this working with just a few words, do the rest of the assignment, then come back to finish this for fun.

  2. If a word begins with a capital letter, then when you translate it, it should also begin with a capital letter. Ignore the case of the rest of the word. In other words, translate "Where" / "WHERE" / "WhErE" / "WhERE" / etc. as "Whar", but translate "where" / "wHERE" / "wHeRe" / "wHere" / etc. as "whar". You should only output "Whar" or "whar" as a translation for any form of "where" -- none of the other letters in "Whar" or "whar" should ever be capitalized apart from possibly the first. (You should definitively not do this by testing individually for all possible ways the word "WhErE" might appear. You'll have over 1000 cases for "restaurant" if you do it that way.)

  3. (This part is optional, for now) Pirates have a habit of saying "Arrr" a lot. Get your translator to randomly insert "Arrr." between sentences. Anytime you encounter the end of a sentence (as denoted by a period, question mark, or exclamation point), decide with a 50/50 chance whether to insert an "Arrr."

Some assistance

A considerable challenge in writing a program like this is to be able to separate the words from the punctuation. Java has built in capabilities for doing so. This SeparateWords.java program will read in text from a file and separate out the words from the punctuation and spaces between them, and print it back out to the screen with a "/" between each so you can see how it separated things. Feel free to take a look and use this if it is helpful, but remember to type in yourself any code that you use (copying and pasting with the mouse tends to make you skip actually learning it, whereas retyping it seems to get it to sink in better.)

The source text for your program should be in a file called source.txt. Your program should grab text from that file and print the translation to the screen. In other words, it should work fairly similarly to the above program; but it shouldn't print out the separator between words and punctuation, and it should translate to pirate-speak.

Wrap up

When finished, use hsp to submit your pirate directory. Indicate in program comments the names of both authors (you and your partner), as well as roughly what fraction of the time each team member spent "driving" at the keyboard. You should be working to give all team members approximately the same amount of time driving.

Good luck, and have fun! Remember that lab assistants are available in the evenings in CMC 306 to help out if you need it.


Many thanks to David Reed at Creighton University for the idea for this assignment!
Available from: Thursday, April 5 2007, 07:20 PM
Due date: Monday, April 9 2007, 11:55 PM