From FANG
|
01 packagepackage is used to name the directory or folder a class is in scg.ch10;
02
03 importimport means to make the classes and/or packages available in this program java.io.File;
04 importimport means to make the classes and/or packages available in this program java.io.FileNotFoundException;
05 importimport means to make the classes and/or packages available in this program java.util.Scanner;
06
07 importimport means to make the classes and/or packages available in this program fang2.core.Game;
08 importimport means to make the classes and/or packages available in this program fang2.sprites.InputStringField;
09
10 /**
11 * A program which reads its command-line arguments, treating each as
12 * the name of a file. An EchoFile object reads its file one line at a
13 * time and echos them to standard output.
14 */
15 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 EchoFileFANG
16 extendsextends means to customize or extend the functionality of a class Game {open braces start code blocks and must be matched with a close brace
17 privateprivate is used to restrict access to the current class only File file;
18 InputStringField iss;
19 @Override
20 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value advance(doubledouble is the type for numbers that can contain decimal fractions dT) {open braces start code blocks and must be matched with a close brace
21 }close braces end code blocks and must match an earlier open brace
22
23 /**
24 * Echo the file to standard output. If there is a problem with the
25 * file not existing or not being readable by the current user, an
26 * appropriate error message should be printed.
27 */
28 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value echo(File file) {open braces start code blocks and must be matched with a close brace
29 ifif executes the next statement only if the condition in parenthesis evaluates to true (file.exists() &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 &&) file.canRead()) {open braces start code blocks and must be matched with a close brace
30 trytry is for executing a code block that may experience exceptions (errors) {open braces start code blocks and must be matched with a close brace
31 Scanner echoScanner =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Scanner(file);
32 String line;
33 whilewhile is a looping structure for executing code repeatedly (echoScanner.hasNextLine()) {open braces start code blocks and must be matched with a close brace
34 line =this assignment operator makes the left side equal to the right side echoScanner.nextLine();
35 System.out.println(line);
36 }close braces end code blocks and must match an earlier open brace
37 echoScanner.close();
38 }close braces end code blocks and must match an earlier open brace catchcatch means to handle an exception that may occur (FileNotFoundException e) {open braces start code blocks and must be matched with a close brace
39 System.out.println("PANIC: This should never happen!");
40 e.printStackTrace();
41 }close braces end code blocks and must match an earlier open brace
42 }close braces end code blocks and must match an earlier open brace elseelse is what happens when the if condition is false {open braces start code blocks and must be matched with a close brace
43 System.out.println("Unable to open \"" +adds two numbers together or concatenates Strings together file.getName() +adds two numbers together or concatenates Strings together
44 "\" for input");
45 }close braces end code blocks and must match an earlier open brace
46 }close braces end code blocks and must match an earlier open brace
47
48 @Override
49 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setup() {open braces start code blocks and must be matched with a close brace
50 }close braces end code blocks and must match an earlier open brace
51 }close braces end code blocks and must match an earlier open brace
52
53 //Uploaded on Mon Mar 29 21:38:37 EDT 2010
|
Download/View scg/ch10/EchoFileFANG.java