Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programing in Java: Suppose that we are working for an online service that provides a bulletin board for its users. We would like to give

Programing in Java:

Suppose that we are working for an online service that provides a bulletin board for its users. We would like to give our users the option of filtering out profanity. Suppose that we consider the word cat to be profane. Write a program that reads a string from the keyboard and test whether the string contain cat. Your program should find words like cAt that differ only in case. Have you program reject only lines that contain cat exactly. For example, concatenation is a small category should not be considered profane. If cat is in the sentence there are several possibilities you must check. If there are only three characters in the string it is profane, if cat is in the middle of the string you must check for _cat_ . If cat is at the beginning you must check for cat space_ If cat is in the beginning you must check for cat_ && test the index to see if it is at the beginning. If _cat is in the string && cat is at the end of the string it will be profane. Strings know their length. Test the index and determine if it is at the end. You can get the location of the last space with the method lastIndexOf( ) Consider using a boolean variable profane to indicate if you found a profane word. Set the value of profane to false when it is declared. If a profane word is found set it to true. At the end of the 4 tests check to see if it is true and if it is, print out a statement saying it is profane and if it is still false print out a statement saying it is not profane. You can also print a statement after each of the 4 tests when it is profane and state the condition that triggered the profanity. if( just cat) SOP (profane) else if(space cat space_) SOP(profane) else if(cat space_ _ and it is at the beginning) SOP(profane) else if(space cat and it is at the end) SOP(profane) else SOP (not profane) There is a String method contains. It has a String parameter and returns a boolean value indicating if the parameter is in the String being examined. Example: if(inputStirng.contains(cat))// will return true if the String cat is in the String inputString.

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

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions

Question

Just be careful not to make any (stupid) choices this week.

Answered: 1 week ago

Question

We dont make refunds on returned merchandise that is soiled.

Answered: 1 week ago