String manipulation refers to the use of methods to manipulate, alter and determine properties of strings.
The following items, which you should read prior to lab, contain information on how to manipulate strings using Java.
Notes on the Java String class:
http://www.csc.calpoly.edu/~csc101/studynotes/Strings.htm
In Lab 6, you will learn how much fun manipulating strings can be. One thing you need to do in preparation for this lab is to understand the rules of Pig Latin.
If a word begins with a consonant, move all of the
characters up to the first vowel to the end of the word
and add "ay".
Examples: bad becomes adbay,
groovy becomes oovygray.
If a word begins with a vowel, write the word and add "way"
Examples: add becomes addway,
office becomes officeway.
Y is not a vowel.
Example: yes becomes esyay.
If there are no vowels in the word, just write the word.
Example: why becomes why.
Now that you know the rules of the Pig Latin world, translate the following paragraph into Pig Latin:
Every monkey would like to be
In my place instead of me
Cause I am the king of bongo, baby
I am the king of bongo bang
(Source: An excerpt of the lyrics from "Bongo Bang" by Manu Chao.)
Given the variable declarations
String s = "Bongo bang is a weird song!?!";answer the following questions:
String t = "I don't want to be a monkey";
String answer;
int ans;
You will be using a subroutine called findFirstVowel that has already been written for you. The subroutine findFirstVowel takes a String as its argument and returns an int that represents the location of the first vowel. You use this integer to determine how to convert the string to Pig Latin.
The code for findFirstVowel and its auxillary function isVowel is below:Example: findFirstVowel("Spartacus") returns 2.
At this point, you need not worry about the how isVowel works.
Now, you need to write a function that takes a word (string s) and returns a string that is the Pig Latin version of the word.
Example: ConvertToPigLatin("apple") returns "appleway".
Notice the different indications for the various cases in the ConvertToPigLatin subroutine. For each case you may need to add an if-else statement to test if the case is true. Within each if statement you will design an algorithm to convert the word to Pig Latin. Note that the first case (when a word starts with a vowel) has already been done for you. As always, it might not be a bad idea to come up with the algorithm in "psuedocode" first and then translate it to Java.
Finish the ConvertToPigLatin subroutine either on paper or in Notepad or some other editor and bring that with you to lab.