CS 6752 Homework 5
Due: Tuesday, October 25 at 1:30 pm

Assignment 5: Talk like a Pirate

In this assignment, you will write a Java program that takes in an ordinary English sentence and translates it to "Pirate-speak." You should employ the following rules in Pirate-speak:

  "and" -> "'n'"
  "is" -> "be"
  "are" -> "be"
  "am" -> "be"
  "my" -> "me"
  "-ing" -> "-in'"
  "you-" -> "ye-"

For example, the words "is", "are", and "am" should all be replaced with "be". You may assume that words are always separated by a single space.

Any word ending in "ing" should have its ending chnaged to "in'". A similar rule applies to words beginning with "you".

Finally, always add "Yarr!" to the front of the pirate sentences. Here are more complete examples:

  Are you listening? -> Yarr! Be ye listenin'?
  Teaching yourself Java is fun. -> Yarr! Teachin' yerself Java be fun.

The capitalization of the output text should match that of the input text too.

Your program should prompt the user to enter a sentence, then it should print out the translation. After that, it should ask the user if they want to translate another sentence, and keep repeating until the user decides to quit.

Requirement: Your program must use two classes, Driver and Pirate. The Driver class should simply have a main method. In it, the main loop of the program should reside and it should get the input string from the user, then it should call into the Pirate class to do the translation and get the resulting string, then the Driver should print the result. The Pirate class models a Pirate and should have a translate method that takes a String as an argument and returns the translated String. Pirate can have any other methods you want to help get the job done.

Notes & Hints:
  • Our lecture slides and the example programs in t-square should help you with structuring your program.
  • You may need to do some clever String operations in this assignment. Look in the Java API and examine the String class to see all the useful methods it provides.

    Turn-in Procedures

    After you have finished the above assignment, turn it in via T-Square. Please name your files Driver.java and Pirate.java.