From ggc
|
01 packagepackage is used to name the directory or folder a class is in intro;
02 //start auto-imports
03 importimport means to make the classes and/or packages available in this program java.util.*;
04 //end auto-imports
05
06
07 /**
08 * All about my application.
09 * @authorthis is the Javadoc tag for documenting who created the source code My Name Here
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 CountBigWords
12 {open braces start code blocks and must be matched with a close brace
13 /**determines the number of big words in a collection of
14 * words. A big word is considered to be a word with 8
15 * or more letters in it.
16 * Examples:
17 * <"Happy", "Sad", "Super-smart"> -> 1
18 * <"Happy-sad", "Super-smart"> -> 2
19 * <"cat", "dog", "bunny"> -> 0
20 * @paramthis is the Javadoc tag for documenting the purpose of parameters words the collection of words to look through
21 * @returns the number of big words in the collection words
22 */
23 publicpublic is used to indicate unrestricted access (any other class can have access) intint is the type for whole numbers and it is short for integer getBigWordCount(ArrayList<String> words)
24 {open braces start code blocks and must be matched with a close brace
25 intint is the type for whole numbers and it is short for integer count=this assignment operator makes the left side equal to the right side0;
26 forfor is a looping structure for repeatedly executing a block of code(String single: words)
27 //for(int i=0; i<words.size(); i++)
28 //{
29 // String single=words.get(i);
30 {open braces start code blocks and must be matched with a close brace
31 ifif executes the next statement only if the condition in parenthesis evaluates to true(single.length()>=this evaluates to true if the left side is not less than the right side8)
32 {open braces start code blocks and must be matched with a close brace
33 count++this is the increment operator, which increases the variable by 1;
34 }close braces end code blocks and must match an earlier open brace
35 }close braces end code blocks and must match an earlier open brace
36 returnreturn means to provide the result of the method and/or cease execution of the method immediately count;
37 }close braces end code blocks and must match an earlier open brace
38
39 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)
40 {open braces start code blocks and must be matched with a close brace
41 ArrayList<String> words=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<String>();
42 words.add("Happy");
43 words.add("Sad");
44 words.add("Bunnty");
45 CountBigWords counter=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor CountBigWords();
46 intint is the type for whole numbers and it is short for integer count=this assignment operator makes the left side equal to the right sidecounter.getBigWordCount(words);
47 System.out.println("The number of big words is "+adds two numbers together or concatenates Strings togethercount);
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 intro/CountBigWords.java