Design a program that performs two task: 1. accepts as input a sentence in which
ID: 3570318 • Letter: D
Question
Design a program that performs two task:
1. accepts as input a sentence in which all of the words are run together, but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRoses." would be converted to "Stop and smell the roses." (hint: the toLower library function can be used to convert a single uppercase character to it's lowercase.)
2. uses the result of the first part as input and converts each word to "Pig Latin". In one version of Pig Latin you convert a word by removing the first letter, placing that letter at the end of the word, and then appending "ay" to the word. Here is an example:
English: Stop and smell the roses
Pig Latin: topSay ndaay mellsay hetay osesray
Pseudocode and flowchart(raptor file if possible) please
Explanation / Answer
1.
my_string = "StopAndSmellTheRoses"
i = 0
result = ""
for c in my_string:
if c.isupper() and i > 0:
result += " "
result += c.lower()
else:
result += c
i += 1
print result
2.
list-of-consonants = []
index = 0
while(current-letter.is-consonant) do
list-of-consonants.add(current-letter)
index++
end
output-string = original-word.substring-starting-at(index) concat-with "-" concat-with list-of-consonants concat-with "ay"
Programmatic Explaination:
String s;
char firstChar = s.charAt(0);
String piglatin = s.substring(1) + "-" + firstChar + "ay";
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.