From ggc
|
01 packagepackage is used to name the directory or folder a class is in intermediate;
02
03
04 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 MyTest extendsextends means to customize or extend the functionality of a class DefiniteNumericCollectionTest
05 {open braces start code blocks and must be matched with a close brace
06
07 @Override
08 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value runTests(DefiniteNumericCollection collection)
09 {open braces start code blocks and must be matched with a close brace
10 trytry is for executing a code block that may experience exceptions (errors)
11 {open braces start code blocks and must be matched with a close brace
12 runEmptyTest(collection);
13 }close braces end code blocks and must match an earlier open brace
14 catchcatch means to handle an exception that may occur(Exception e)
15 {open braces start code blocks and must be matched with a close brace
16 failed.add("Average test for NaN on empty collection (Exception occurred).");
17 }close braces end code blocks and must match an earlier open brace
18 //try
19 //{
20 runOneElementTest(collection);
21 //}
22 //catch(Exception e)
23 //{
24 // failed.add("Average test for collection {5} (Exception occurred).");
25 //}
26 }close braces end code blocks and must match an earlier open brace
27
28 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value runEmptyTest(DefiniteNumericCollection collection)
29 {open braces start code blocks and must be matched with a close brace
30 collection.clear();
31 ifif executes the next statement only if the condition in parenthesis evaluates to true(Double.isNaN(collection.getAverage().doubleValue()))
32 {open braces start code blocks and must be matched with a close brace
33 passed.add("Average test for NaN on empty collection.");
34 }close braces end code blocks and must match an earlier open brace
35 elseelse is what happens when the if condition is false
36 {open braces start code blocks and must be matched with a close brace
37 failed.add("Average test for NaN on empty collection.");
38 }close braces end code blocks and must match an earlier open brace
39
40 }close braces end code blocks and must match an earlier open brace
41
42 privateprivate is used to restrict access to the current class only voidvoid means the method does not return a value runOneElementTest(DefiniteNumericCollection collection)
43 {open braces start code blocks and must be matched with a close brace
44 collection.clear();
45 collection.add(newnew is used to create objects by calling the constructor Integer(5));
46 ifif executes the next statement only if the condition in parenthesis evaluates to true(collection.getAverage().intValue()==this is the comparison operator which evaluates to true if both sides are the same5)
47 {open braces start code blocks and must be matched with a close brace
48 passed.add("Average test for collection {5}.");
49 }close braces end code blocks and must match an earlier open brace
50 elseelse is what happens when the if condition is false
51 {open braces start code blocks and must be matched with a close brace
52 failed.add("Average test for collection {5}.");
53 }close braces end code blocks and must match an earlier open brace
54
55 }close braces end code blocks and must match an earlier open brace
56
57 /**
58 * @paramthis is the Javadoc tag for documenting the purpose of parameters args
59 */
60 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)
61 {open braces start code blocks and must be matched with a close brace
62 DefiniteNumericCollectionTest test=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor MyTest();
63 DefiniteNumericCollection collection;
64 collection=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor MyDefiniteNumericCollection();
65 test.runTests(collection);
66 }close braces end code blocks and must match an earlier open brace
67
68 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/MyTest.java