intermediate/CensorIt

From ggc

Jump to: navigation, search

01 package intermediate;
02 
03 import wiki.Wiki;
04 
05 /**
06  * All about my application.
07  @author My Name Here
08  */
09 public class CensorIt
10 {
11   //precondition: badWords has zero or more words and webText
12   //is a non-empty string
13   //postcondition: returns true when webText has no badWords
14   //in it, returns false if there is any badWord in webText
15   public boolean isOkayForChildren(String[] badWords, String webText)
16   {
17     for(int i=0; i<badWords.length; i++)
18     {
19       if(webText.contains(badWords[i]))
20       {
21         return false;
22       }
23     }
24     return true;
25   }
26 
27   public static void main(String[] args)
28   {
29     String[] badWords={"kill""adult"};
30     String webText="The baby dog was sick.";
31     CensorIt censor=new CensorIt();
32     if(censor.isOkayForChildren(badWords, webText))
33     {
34       Wiki.out.println(webText);
35     }
36     else
37     {
38       Wiki.out.println("Censored!!");
39     }
40     webText=webText.replaceAll("baby""baba");
41     Wiki.out.println(webText);
42   }
43 }


Download/View intermediate/CensorIt.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter