Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started