Lab Set Q1W7

advertisement
Lab Set Q1W7
Advanced Strings
Complete the following methods in the StringPractice Class.
Level 1
Name:
printOutEachChar
Input:
String word
Output:
nothing
Action:
print out all the letters in the string on separate lines. So the String “Cat” would print out:
Char 1: C
Char 2: a
Char 3: t
Name:
Input:
Output:
Action:
printOutInReverse
String word
nothing
print out the string in reverse.
Level 2
Name:
countVowels
Input:
String word
Output:
int countOfVowels
Action:
counts the number of vowels in the word passed in. Assume that there can be both upper
and lower case vowels.
Name:
countConsonants
Input:
String word
Output:
int countOfConsonants
Action:
count the number of consonants in the word passed in. Assume that there can be both
upper and lower case consonants. Also assume that there are no special characters. (Hint – there is a
supper easy way to program this method)
Level 3
Name:
printWords
Input:
String word
Output:
nothing
Action:
print out the words in the string on separate lines. So the String “My code won’t
compile” would print:
Word 1: My
Word 2: code
Word 3: won’t
Word 4: compile
Level 4
Name:
Input:
Output:
Action:




pigLatinateWord
String word
String result
takes in a word and does the following:
The word will have the first letter removed to the front and placed at the back and then an
“ay” added to the end. So “happy” becomes “appyhay”.
If a word starts with a vowel then it remains at the beginning but it is also still placed at the
end with a “hay” added instead of an “ay”. So “orbit” becomes “orbitohay”.
If there is more than one consonant at the beginning then each consonant until the first
vowel gets moved to the end with an “ay” still added. So “scram” becomes “amscray”
You do not need to worry about capital letters or punctuation
Level 5
Name:
Input:
Output:
Action:
pigLatinateText
String word
String result
takes in text and pigLatinates each word in the text.
 You do need to worry about punctuation and capital letters.
Download