From ggc
|
01 packagepackage is used to name the directory or folder a class is in FA;
02
03
04 /**
05 * This program will read a line of string data from one file and a pairs of strings from
06 * a second file. The pairs of strings contain a target and replacement. Each example
07 * of a string target is replaced by the corresponding string, replacement.
08 * @authornull Frank Anderson
09 */
10 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 FileTransformer
11 {open braces start code blocks and must be matched with a close brace
12 publicpublic is used to indicate unrestricted access (any other class can have access) FileTransformer()
13 {open braces start code blocks and must be matched with a close brace
14 String sourceFile;
15 String originalText;
16 ArrayList<String> replacements;
17 System.out.println("Hello JavaWIDE!");
18 /** Read text from the sourceFile and store into originalText. */
19 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setSourceFile(String fileForText)
20 {open braces start code blocks and must be matched with a close brace
21 sourceFile=this assignment operator makes the left side equal to the right sidefileForText;
22 Scanner scannerSource=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Scanner(sourceFile);
23 originalText=this assignment operator makes the left side equal to the right sidescannerSource.next();
24 }close braces end code blocks and must match an earlier open brace
25 /** Takes a single string form a file and read the data into an ArrayList.*/
26
27 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value addReplacements(String fileForReplacements)
28 {open braces start code blocks and must be matched with a close brace
29 Scanner scannerReplacements =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Scanner(fileForReplacements);
30 whilewhile is a looping structure for executing code repeatedly(scannerReplacements.hasNext())
31 replacements.addNext();
32 }close braces end code blocks and must match an earlier open brace
33
34 /**Converts the originalText using replacements and returns the result as a string.*/
35 publicpublic is used to indicate unrestricted access (any other class can have access) String getTransformedText(String original, String frist, String replaceWith)
36 {open braces start code blocks and must be matched with a close brace
37 String string2=this assignment operator makes the left side equal to the right side"";
38 string2=this assignment operator makes the left side equal to the right sideoriginalText;
39 forfor is a looping structure for repeatedly executing a block of code(Replacer single; replacements)
40 {open braces start code blocks and must be matched with a close brace
41 Replacer model=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Replacer(single);
42 string2=this assignment operator makes the left side equal to the right sidemodel.getReplaced(string2);
43 }close braces end code blocks and must match an earlier open brace
44 System.out.println(string2);
45 }close braces end code blocks and must match an earlier open brace
46
47
48 }close braces end code blocks and must match an earlier open brace
49 }close braces end code blocks and must match an earlier open brace
|
Download/View FA/FileTransformer.java