From ggc
|
01 packagepackage is used to name the directory or folder a class is in intermediate;
02 //start auto-imports
03 importimport means to make the classes and/or packages available in this program java.awt.*;
04 importimport means to make the classes and/or packages available in this program java.util.*;
05 //end auto-imports
06
07
08 /**
09 * All about my application.
10 * @authornull My Name Here
11 */
12 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 OrderedCollection<T extendsextends means to customize or extend the functionality of a class Comparable, V>
13 {open braces start code blocks and must be matched with a close brace
14 privateprivate is used to restrict access to the current class only ArrayList<T> collect;
15 privateprivate is used to restrict access to the current class only ArrayList<V> values;
16
17 publicpublic is used to indicate unrestricted access (any other class can have access) OrderedCollection()
18 {open braces start code blocks and must be matched with a close brace
19 collect=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<T>();
20 values=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<V>();
21 }close braces end code blocks and must match an earlier open brace
22
23 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value insert(T t, V v)
24 {open braces start code blocks and must be matched with a close brace
25 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<collect.size(); i++this is the increment operator, which increases the variable by 1)
26 {open braces start code blocks and must be matched with a close brace
27 ifif executes the next statement only if the condition in parenthesis evaluates to true(collect.get(i).compareTo(t)>0)
28 {open braces start code blocks and must be matched with a close brace
29 collect.add(i, t);
30 values.add(i, v);
31 returnreturn means to provide the result of the method and/or cease execution of the method immediately;
32 }close braces end code blocks and must match an earlier open brace
33 }close braces end code blocks and must match an earlier open brace
34 values.add(v);
35 collect.add(t);
36 }close braces end code blocks and must match an earlier open brace
37
38 publicpublic is used to indicate unrestricted access (any other class can have access) String toString()
39 {open braces start code blocks and must be matched with a close brace
40 String output=this assignment operator makes the left side equal to the right side"[";
41 forfor is a looping structure for repeatedly executing a block of code(intint is the type for whole numbers and it is short for integer i=this assignment operator makes the left side equal to the right side0; i<collect.size(); i++this is the increment operator, which increases the variable by 1)
42 {open braces start code blocks and must be matched with a close brace
43 output+=this increases the variable on the left by the value on the right"("+adds two numbers together or concatenates Strings togethercollect.get(i).toString()+adds two numbers together or concatenates Strings together", "+adds two numbers together or concatenates Strings togethervalues.get(i).toString()+adds two numbers together or concatenates Strings together"), ";
44 }close braces end code blocks and must match an earlier open brace
45 output+=this increases the variable on the left by the value on the right"]";
46 returnreturn means to provide the result of the method and/or cease execution of the method immediately output;
47 }close braces end code blocks and must match an earlier open brace
48
49 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)
50 {open braces start code blocks and must be matched with a close brace
51 OrderedCollection<String, Integer> ordered=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor OrderedCollection<String, Integer>();
52 ordered.insert("Howdy", 56);
53 ordered.insert("Apples", 76);
54 ordered.insert("Doody", 96);
55 System.out.println(ordered);
56 }close braces end code blocks and must match an earlier open brace
57 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/OrderedCollection.java