Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program that replaces certain words and phrases in a sentence with other words and phrases: Specification: 1. Replace moron with unwise person

Write a java program that replaces certain words and phrases in a sentence with other words and phrases:

Specification:

1.

Replace "moron" with "unwise person"

Replace "idiot" with "silly"

Replace "stupid" with "unwise"

Replace "ugly" with "uniquely beautiful"

Replace "fake" with "innovative

2. Embedded words - If someone embeds one of those words in some other word, like "That was a real fakeout by their forward", there is no need to convert the sentence to "That was a real innovativeout by their forward".

3. Unwise unwise - If someone inputs "stupid moron" in a phrase, the replacement should be "unwise person" instead of "unwise unwise person".

4. Prior word adjustments - If someone inputs "He's such a moron!", the replacement should be "He's such an unwise person!"; similarly, if someone inputs "That person is such an idiot!", the replacement should be "That person is such a silly!".

5. Uppercase and Lowercase - If a word is the first word of a sentence, it should have a capital first letter in the replacement. Otherwise, it should be all lowercase. If the user does something weird "He is a MorON" it should be converted to "He is a moron".

6. Write a helper method to assist with the work. The main method locates each word in the phrase, as it finds a word that needs to be replaced, it calls a helper method to replace that word. Declare appropriate class constants (e.g., IDIOT_REPLACE) for the replacement words.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Run:

Enter a string: OMG. That ugly person is a stupid idiot.

Revised Text: OMG. That uniquely beautiful person is an unwise silly.

Enter a string: Moron is Ugly.

Revised Text: Unwise person is uniquely beautiful.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions