From ggc
|
01 packagepackage is used to name the directory or folder a class is in jam;
02
03 importimport means to make the classes and/or packages available in this program java.io.*;
04 importimport means to make the classes and/or packages available in this program java.net.*;
05 importimport means to make the classes and/or packages available in this program java.util.*;
06 importimport means to make the classes and/or packages available in this program wiki.Wiki;
07 /**
08 * All about my classclass is a group of fields and methods used for making objects here.
09 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
10 */
11 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 RandomPhraseGenerator
12 {open braces start code blocks and must be matched with a close brace
13 privateprivate is used to restrict access to the current class only String textFile;
14 privateprivate is used to restrict access to the current class only ArrayList<String> phrases;
15 privateprivate is used to restrict access to the current class only Random random;
16
17 publicpublic is used to indicate unrestricted access (any other class can have access) RandomPhraseGenerator(String filename)
18 {open braces start code blocks and must be matched with a close brace
19 //wiki.Wiki.BASE_URL="http://ggc.javawide.org/media.php?f=";
20 phrases=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<String>();
21 random=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Random();
22 loadFile(filename);
23 }close braces end code blocks and must match an earlier open brace
24
25 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value loadFile(String filename)
26 {open braces start code blocks and must be matched with a close brace
27 textFile=this assignment operator makes the left side equal to the right sidefilename;
28 trytry is for executing a code block that may experience exceptions (errors)
29 {open braces start code blocks and must be matched with a close brace
30 Scanner fromFile=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Scanner(Wiki.getInputStream(textFile));
31 fromFile.useDelimiter("\n");
32 whilewhile is a looping structure for executing code repeatedly(fromFile.hasNext())
33 {open braces start code blocks and must be matched with a close brace
34 phrases.add(fromFile.next().trim());
35 }close braces end code blocks and must match an earlier open brace
36 }close braces end code blocks and must match an earlier open brace
37 catchcatch means to handle an exception that may occur(IOException ioe)
38 {open braces start code blocks and must be matched with a close brace
39 ioe.printStackTrace();
40 }close braces end code blocks and must match an earlier open brace
41 }close braces end code blocks and must match an earlier open brace
42
43 publicpublic is used to indicate unrestricted access (any other class can have access) String getRandomPhrase()
44 {open braces start code blocks and must be matched with a close brace
45 returnreturn means to provide the result of the method and/or cease execution of the method immediately phrases.get(random.nextInt(phrases.size()));
46 }close braces end code blocks and must match an earlier open brace
47 }close braces end code blocks and must match an earlier open brace
|
Download/View jam/RandomPhraseGenerator.java