From ggc
|
01 packagepackage is used to name the directory or folder a class is in intermediate;
02
03 importimport means to make the classes and/or packages available in this program wiki.Wiki;
04
05 /**
06 * All about my application.
07 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
08 */
09 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects CensorIt
10 {open braces start code blocks and must be matched with a close brace
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 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false isOkayForChildren(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays badWords, String webText)
16 {open braces start code blocks and must be matched with a close brace
17 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<badWords.length; i++this is the increment operator, which increases the variable by 1)
18 {open braces start code blocks and must be matched with a close brace
19 ifif executes the next statement only if the condition in parenthesis evaluates to true(webText.contains(badWords[brackets are typically used to declare, initialize and index (indicate which element of) arraysi]brackets are typically used to declare, initialize and index (indicate which element of) arrays))
20 {open braces start code blocks and must be matched with a close brace
21 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
22 }close braces end code blocks and must match an earlier open brace
23 }close braces end code blocks and must match an earlier open brace
24 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
25 }close braces end code blocks and must match an earlier open brace
26
27 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
28 {open braces start code blocks and must be matched with a close brace
29 String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays badWords=this assignment operator makes the left side equal to the right side{open braces start code blocks and must be matched with a close brace"kill", "adult"}close braces end code blocks and must match an earlier open brace;
30 String webText=this assignment operator makes the left side equal to the right side"The baby dog was sick.";
31 CensorIt censor=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor CensorIt();
32 ifif executes the next statement only if the condition in parenthesis evaluates to true(censor.isOkayForChildren(badWords, webText))
33 {open braces start code blocks and must be matched with a close brace
34 Wiki.out.println(webText);
35 }close braces end code blocks and must match an earlier open brace
36 elseelse is what happens when the if condition is false
37 {open braces start code blocks and must be matched with a close brace
38 Wiki.out.println("Censored!!");
39 }close braces end code blocks and must match an earlier open brace
40 webText=this assignment operator makes the left side equal to the right sidewebText.replaceAll("baby", "baba");
41 Wiki.out.println(webText);
42 }close braces end code blocks and must match an earlier open brace
43 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/CensorIt.java