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.math.*;
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 * @authorthis is the Javadoc tag for documenting who created the source code 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 NumberExplore
13 {open braces start code blocks and must be matched with a close brace
14 staticstatic means that an instance is not required for access (class level access) classclass is a group of fields and methods used for making objects NumberComparator
15 implementsimplements means providing method bodies for the methods declared in the corresponding interface Comparator<Number>
16 {open braces start code blocks and must be matched with a close brace
17 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 compare(Number a, Number b)
18 {open braces start code blocks and must be matched with a close brace
19 BigDecimal bigA;
20 ifif executes the next statement only if the condition in parenthesis evaluates to true(a instanceofinstanceof is an operator for determining if the types are compatible BigDecimal) bigA=this assignment operator makes the left side equal to the right side(BigDecimal)a;
21 elseelse is what happens when the if condition is false bigA=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor BigDecimal(a.doubleValue());
22
23 BigDecimal bigB;
24 ifif executes the next statement only if the condition in parenthesis evaluates to true(b instanceofinstanceof is an operator for determining if the types are compatible BigDecimal) bigB=this assignment operator makes the left side equal to the right side(BigDecimal)b;
25 elseelse is what happens when the if condition is false bigB=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor BigDecimal(b.doubleValue());
26
27 //BigDecimal result=bigA.subtract(bigB);
28 returnreturn means to provide the result of the method and/or cease execution of the method immediately bigA.compareTo(bigB);
29 //double result=a.doubleValue()-b.doubleValue();
30 //if(result<0) return -1;
31 //else if(result>0) return 1;
32 //return 0;
33 }close braces end code blocks and must match an earlier open brace
34 }close braces end code blocks and must match an earlier open brace
35
36 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)
37 {open braces start code blocks and must be matched with a close brace
38 ArrayList<Number> all=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor ArrayList<Number>();
39 all.add(5.6);
40 System.out.println(all.get(0));
41 ifif executes the next statement only if the condition in parenthesis evaluates to true(all.get(0) instanceofinstanceof is an operator for determining if the types are compatible Double) System.out.println("Its a happy baby double");
42 all.add(newnew is used to create objects by calling the constructor Double(7.7));
43 all.add(newnew is used to create objects by calling the constructor Double(4.5));
44 System.out.println(all);
45 Collections.sort(all, newnew is used to create objects by calling the constructor NumberComparator());
46 System.out.println(all);
47 Number number=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Double(6.8);
48 doubledouble is the type for numbers that can contain decimal fractions x=this assignment operator makes the left side equal to the right sidenumber.doubleValue();
49 Number two=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Double(6.6);
50 ifif executes the next statement only if the condition in parenthesis evaluates to true(number.doubleValue()>two.doubleValue())
51 {open braces start code blocks and must be matched with a close brace
52 System.out.println("Greater");
53 }close braces end code blocks and must match an earlier open brace
54 elseelse is what happens when the if condition is false
55 {open braces start code blocks and must be matched with a close brace
56 System.out.println("Lesser");
57 }close braces end code blocks and must match an earlier open brace
58 System.out.println("number is "+adds two numbers together or concatenates Strings togetherx);
59
60 Number a=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Double(Double.POSITIVE_INFINITY);
61 BigDecimal b=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor BigDecimal(Double.MAX_VALUE);
62 Number c=this assignment operator makes the left side equal to the right sideb.add(b);
63 System.out.println("a is "+adds two numbers together or concatenates Strings togethera);
64 System.out.println("b is "+adds two numbers together or concatenates Strings togetherb);
65 System.out.println("c is "+adds two numbers together or concatenates Strings togetherc);
66 System.out.println("a.doubleValue() is "+adds two numbers together or concatenates Strings togethera.doubleValue());
67 System.out.println("b.doubleValue() is "+adds two numbers together or concatenates Strings togetherb.doubleValue());
68 System.out.println("c.doubleValue() is "+adds two numbers together or concatenates Strings togetherc.doubleValue());
69 ifif executes the next statement only if the condition in parenthesis evaluates to true(a instanceofinstanceof is an operator for determining if the types are compatible BigDecimal) System.out.println("a is a big decimal");
70 ifif executes the next statement only if the condition in parenthesis evaluates to true(b instanceofinstanceof is an operator for determining if the types are compatible BigDecimal) System.out.println("b is a big decimal");
71 ifif executes the next statement only if the condition in parenthesis evaluates to true(c instanceofinstanceof is an operator for determining if the types are compatible BigDecimal) System.out.println("c is a big decimal");
72
73 //all.add(a);
74 all.add(c);
75 all.add(b);
76 System.out.println(all);
77 Collections.sort(all, newnew is used to create objects by calling the constructor NumberComparator());
78 System.out.println(all);
79
80 }close braces end code blocks and must match an earlier open brace
81 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/NumberExplore.java