Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose that we are working for an online service that provides a bulletin board

ID: 3542489 • Letter: S

Question

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 words Cat, dog and Llama to be profane. Write a program that reads a string from the keyboard and tests whether the string contains one of the profane words. Your program should find words like cAt that differ only in case.

Optional: As an extra challenge, have your program reject only lines that contain a profane word exactly. For example, Dogmatic concatenation is a small category. This sentence should not be considered profane

please do the extra challenge while writing the program.

Explanation / Answer

import java.util.Scanner;


public class CS1_Javed_X7_1


{


public static void main(String[] args)


{


String a;


int case_num = 0;



Scanner keyboard = new Scanner(System.in);


System.out.println("Enter a sentence:");


a = keyboard.nextLine();


a = a.toLowerCase();


  


if (a.indexOf("cat") != -1) //this section detects for the profane words


case_num = 1;


else if (a.indexOf("dog") != -1)


case_num = 1;


else if (a.indexOf("llama") != -1)


case_num = 1;


  


switch(case_num) //This secton gets the correct message to print.


{


case 1:


System.out.println("your sentence consists of profanity");


break;


default:


System.out.println("No profanity detected in the Sentence");


}



}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote