CSCI 161 — Lab 7

Due: Tuesday, October 31, 2017 @ 10:00AM

Overview

Write a program that translates an English word into a Pig Latin word. Input ONE, and ONLY one, word from the user, and then output its translation to Pig Latin.

The rules for converting a word to Pig Latin follow.

  1. The general form for converting a word is to remove the first letter. Then append to the end of the word a hyphen, followed by the first letter that was removed, followed by "ay". For example, "robot" becomes "obot-ray" and "Hello" becomes "ello-Hay".
  2. If the word begins with a vowel (an element of "aeiouAEIOU") simply append "-way". For example, "example" becomes "example-way" and "All" becomes "All-way".
  3. If the word begins with "th" (or "Th", "tH", or "TH"), remove the prefix and append "-thay" (or "-Thay", "-tHay", or "-THay") to the word. For example, "this" becomes "is-thay" and "The" becomes "e-Thay".

Use at least the REQUIRED METHODS listed below, with the exact same SPELLING for method names and parameters.

Input Specification

Input ONE English word as a string. If multiple words are entered ignore any beyond the first.

Use PRECISELY the format below with the EXACT same SPACING and SPELLING.

Please enter a word ==> <user input>

Output Specification

Output an introductory message, a prompt for the English word, and a translation for the inputted word.

Use PRECISELY the format below with the EXACT same SPACING and SPELLING. The output below assumes the user entered "Hunger".

This program will convert an English word into Pig Latin.

Please enter a word ==> Hunger

"Hunger"
  in Pig Latin is
"unger-Hay"

Required Methods

// Prompt and read a word to translate
public static String  readWord (Scanner console)

// Convert a word to Pig Latin and return it
public static String  convertWord (String englishWord)

// Return true if "c" is a vowel, false otherwise.
// Handle both lowercase and uppercase letters.
public static boolean isVowel (char c)

// Print result of translation
public static void printResult (String englishWord, String pigLatinWord)

Hints

BEFORE you start coding, think about which methods each method will call. Which methods should "main" call? Create a diagram which shows the calling relationships.

There are many useful String methods listed HERE. You may find startsWith and charAt helpful.

Style

Use good programming style:

Submission

Please name your program PigLatin.java

Submit the Java source code file on Autolab under the "Lab 7" assignment.

Grading