From ggc
|
01 packagepackage is used to name the directory or folder a class is in FA;
02
03
04 /**
05 * AltProject Writing Replacer classclass is a group of fields and methods used for making objects.
06 * @authorthis is the Javadoc tag for documenting who created the source code Frank Anderson
07 */
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 Replacer
10 {open braces start code blocks and must be matched with a close brace
11 /** target is the section of string to be replaced */
12 String target;
13 /**targed is replaced with the string, replacement. */
14 String replacement;
15 /** phrase is the string that is brought in transferred to Replacer.*/
16 String phrase;
17
18 /** Replacer brings in the value of two string into the program and constructs
19 * the string target and replacement. */
20 /** a is the expression to be replaced in the string.*/
21 /** b is the replacement forfor is a looping structure for repeatedly executing a block of code string a. */
22 publicpublic is used to indicate unrestricted access (any other class can have access) Replacer(String a, String b)
23 {open braces start code blocks and must be matched with a close brace
24 target =this assignment operator makes the left side equal to the right side a;
25 replacement =this assignment operator makes the left side equal to the right side b;
26 }close braces end code blocks and must match an earlier open brace
27 /** getReplaced brings in the string, source. It will then replace every
28 * substring equal to target with replacement and then returnreturn means to provide the result of the method and/or cease execution of the method immediately the
29 * newnew is used to create objects by calling the constructor string to the program which invoked thisthis means the current object (the implicit parameter) method. */
30 /** @ param source is the string whose characters are changed in phrase.*/
31 /**@ returnreturn means to provide the result of the method and/or cease execution of the method immediately the phrase to the calling program.*/
32 publicpublic is used to indicate unrestricted access (any other class can have access) String getReplaced(String source)
33 {open braces start code blocks and must be matched with a close brace
34 phrase=this assignment operator makes the left side equal to the right sidesource;
35 booleanboolean is a type that is either true or false more =this assignment operator makes the left side equal to the right side truetrue is the boolean value that is the opposite of false;
36
37 /** If the length of phrase is less than the length of target, then target
38 * can not be a substring of phrase. Return phrase.*/
39 ifif executes the next statement only if the condition in parenthesis evaluates to true (phrase.length() < target.length())
40 returnreturn means to provide the result of the method and/or cease execution of the method immediately phrase;
41
42 /** If phrase and target are the same, returnreturn means to provide the result of the method and/or cease execution of the method immediately phrase. */
43 ifif executes the next statement only if the condition in parenthesis evaluates to true((phrase.length()==this is the comparison operator which evaluates to true if both sides are the sametarget.length())&this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&)(target.equals(phrase)))
44 returnreturn means to provide the result of the method and/or cease execution of the method immediately replacement;
45
46 /** Search phrase forfor is a looping structure for repeatedly executing a block of code all occurrences of target and replace with replacemet. */
47 whilewhile is a looping structure for executing code repeatedly (more)
48 {open braces start code blocks and must be matched with a close brace
49 //System.out.println("Phrase is "+phrase);
50 more=this assignment operator makes the left side equal to the right sidefalsefalse is a value for the boolean type and means not true;
51 ifif executes the next statement only if the condition in parenthesis evaluates to true(phrase.indexOf(target)>=this evaluates to true if the left side is not less than the right side0)
52 {open braces start code blocks and must be matched with a close brace
53 phrase=this assignment operator makes the left side equal to the right sidephrase.substring(0,phrase.indexOf(target))+adds two numbers together or concatenates Strings together replacement +adds two numbers together or concatenates Strings togetherphrase.substring(phrase.indexOf(target)+adds two numbers together or concatenates Strings togethertarget.length());
54 more=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
55 }close braces end code blocks and must match an earlier open brace
56
57 }close braces end code blocks and must match an earlier open brace
58 returnreturn means to provide the result of the method and/or cease execution of the method immediately phrase;
59 }close braces end code blocks and must match an earlier open brace
60
61 }close braces end code blocks and must match an earlier open brace
|
Download/View FA/Replacer.java