Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inflationary Language  RSS feed

 
Megan Long
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
these are the instructions:
Write a program that accepts a sentence, searches the sentence for the sounds represented by the
substrings "one" and "won", and replaces those substrings with inflationary language. Replace all
occurrences of "one" with "two" and replace all occurrences of "won" with "ten". If the input sentence
contains neither substring, print out a message that inflation hasn't hit that sentence yet. (See sample
output for more details.)
Your program should find substring matches for "one" and "won" regardless of case, and it should
output an inflated sentence with a capital letter at the beginning of the sentence.

And this is an example of what it's supposed to look like:
Please enter a sentence with a numerical sound:
One fish, two fish.
Mild Inflation! That phrase is now: Two fish, two fish.
Please enter a sentence with a numerical sound:
What a wonderful song!
Rampant Inflation!!! That phrase is now: What a tenderful song!
Please enter a sentence with a numerical sound:
Please don't be late.
Whew! Inflation hasn't hit that sentence yet!
Please enter a sentence with a numerical sound:
5,6,7,8... ONE! Singular sensation!
Mild Inflation! That phrase is now: 5,6,7,8... two! Singular
sensation!
Please enter a sentence with a numerical sound:
'tis WONDERFUL! 'tis Glorious!
Rampant Inflation!!! That phrase is now: 'tis tenderful! 'tis
glorious!
Please enter a sentence with a numerical sound:
Happy things! One: It's a wonderful day!
Mild Inflation! That phrase is now: Happy things! two: it's a
wonderful day! Rampant Inflation!!! That phrase is now: Happy things!
two: it's a tenderful day!


I'm not sure how to code it so it will pick out the words and swap them? I'm not that good with Strings yet and just started in Java so any help is appreciated! Thank you.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Turn your computer off. Get a pencil and paper and write down how you would do that without a computer. Make the instructions really simple, so even I can understand them. Then you will be able to convert the instructions to code easily.
 
Junilu Lacar
Sheriff
Posts: 11169
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Study the String API: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html - you should be able to find some methods in there that will help you complete this task.

Just out of curiosity, what is the program supposed to do with this kind of input: "It has been one wonderful day, said Mr. Wong, but now it's done."

Should the program say "Mild inflation!" or "Rampant Inflation!" or "Mild and Rampant Inflation!"?

If I understand the requirements correctly, the program should output this: 

"(what?) inflation! That phrase is now: It has been two tenderful day, said mr. teng, but now it's dtwo."
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally think the most useful part of the String API for the current exercise might be the “See also” links.
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The instructions specify finding parts of the sentence that SOUND LIKE "one" and "won". That is very difficult thing to do. How would you "inflate" this sentence:
"I have a cone and a wonton."

If the correct answer is "I have a ctwo and a tenton" then the part of the instruction that mentions sound is superfluous and it should just be "replace the sequence 'one' with the sequence 'two' and the sequence 'won' with the sequence 'ten'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!