International Talk Like a Pirate Day was back in September. The class example on 11/9 was based on this day.
If you haven't heard of this holiday, it is a silly one. In 1995, John Baur and Mark Summers invented a new holiday, International Talk Like a Pirate Day. As they proposed it, on every September 19th, people around the world would be encouraged to talk like a pirate (with lots of "Arrrrs" and "Ahoys" and the like). At the official Talk Like a Pirate Day Web site, www.talklikeapirate.com, you can read about the history of the holiday, order official merchandise, and even experiment with a simple Web page that translates simple English phrases into pirate talk. If you want to know how to chat like a pirate, karateparty.org has a guide to pirate leet speak.
The classroom example involved implementing a simple textual translator that can read in plain English text and translate it into Pirate talk. Nothing fancy here--just reading in words from a Scanner, translating those you can, and sending the results to a PrintWriter.
For those who found the example interesting, the information below is provided for reference. It includes a table of possible translations that was used in an assignment in another course. You're welcome to build on this idea for your Program 5 if you like.
First, note that we're going to use a very simple plain-text input format. Imagine that the input text consists of a series of words separated by white space (one or more spaces, tabs, newlines, etc.). A word is just a series of consecutive non-whitespace characters (such as letters, digits, punctuation characters, etc.). Here is an example containing four words:
All cows eat grass.
In this example, the last word is "grass.", including the period. Similarly, this example contains three words:
Can't you dance?
Fortunately, a Java Scanner naturally skips over whitespace and grabs the next word from an input stream, so reading the input should be easy.
So what do you translate? Use the following pirate talk translation table:
English word | Pirate translation |
---|---|
hello | ahoy |
hi | yo-ho-ho |
hey | avast |
my | me |
friend | me bucko |
sir | matey |
madam | proud beauty |
stranger | scurvy dog |
officer | foul blaggard |
where | whar |
is | be |
are | be |
the | th' |
you | ye |
your | yer |
you're | ye be |
we're | we be |
old | barnacle-covered |
attractive | comely |
happy | grog-filled |
nearby | broadside |
restroom | head |
restaurant | galley |
hotel | fleabag inn |
bank | buried treasure |
yes | aye |
yes! | aye aye! |
addled | mad |
after | aft |
money | booty |
professor | cap'n |
food | grub |
of | o' |
quickly | smartly |
to | t' |
and | an' |
it's | it be |
right | starboard |
left | port |
anything else not listed | remains unchanged |
Also, to simplify things, let's call a word that does not end in a period a regular word, like "All", "Can't", "cows", and "dance?". In addition, an end-of-sentence word is one that does end in a period, like "grass." in the first example. Thus, a sentence is a sequence of regular words plus one end-of-sentence word.
So, to translate your input stream into pirate talk, just read in a sequence of words. For each word, if it is a regular word, just print out its translation followed by a space. If it is an end-of-sentence word, then print out its translation, followed by " Arrr." and a newline. That way, each sentence in the input will be printed on a separate line. When translating end-of-sentence words, don't consider the period when determining its translation, but do print the period at the end of the word out.
Here are some examples. For this input:
the professor wants to know if there is a restaurant nearby.
The corresponding translation would be:
th' cap'n wants t' know if there be a galley broadside. Arrr.
For this input:
yes there is one on the right side.
The translation would be:
aye there be one on th' starboard side. Arrr.
Also, notice that extra whitespace in the input makes no difference in the output:
yes there is one on the right side.
The translation would still be:
aye there be one on th' starboard side. Arrr.
Finally, you could send arbitrarily amounts of text to the translator, as many lines as you want:
the professor wants to know if there is a restaurant nearby. yes there is one on the right side.
The translation would still be:
th' cap'n wants t' know if there be a galley broadside. Arrr. aye there be one on th' starboard side. Arrr.
Also, note that all of the translations listed, and all of the examples shown here, are in lowercase. This is the minimum level of behavior expected. However, feel free to explore a bit and invent on your own. If you want to tackle mixed-case words, or you want to add additional translations of your own beyond what is listed in the table, or you want to support translating multi-word phrases (i.e., "excuse me" becomes "avast!", etc.), or you want to support proper translation of words that end in commas/semicolons/etc., feel free to do so. Get creative. Add your own flourishes. Have fun with it.