From ggc
|
01 packagepackage is used to name the directory or folder a class is in intermediate;
02
03 importimport means to make the classes and/or packages available in this program wiki.Wiki;
04
05 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 Rank implementsimplements means providing method bodies for the methods declared in the corresponding interface Comparable<Rank>
06 {open braces start code blocks and must be matched with a close brace
07 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer faceValue;
08
09 /**
10 * makes a rank with the number 1-13 where:
11 * 1 is Ace
12 * 2-10 is 2-10
13 * 11 is Jack
14 * 12 is Queen
15 * 13 is King
16 * @paramthis is the Javadoc tag for documenting the purpose of parameters value an integer representing the face value
17 */
18 publicpublic is used to indicate unrestricted access (any other class can have access) Rank(intint is the type for whole numbers and it is short for integer value)
19 {open braces start code blocks and must be matched with a close brace
20 faceValue=this assignment operator makes the left side equal to the right sidevalue;
21 }close braces end code blocks and must match an earlier open brace
22
23 /**
24 * makes a rank given a textual description of the rank.
25 * Valid ranks are "2", "3", ..., "10", "J" or "Jack",
26 * "Q" or "Queen", "K" or "King", "A" or "Ace"
27 * @paramthis is the Javadoc tag for documenting the purpose of parameters name the text description of the rank
28 */
29 publicpublic is used to indicate unrestricted access (any other class can have access) Rank(String name)
30 {open braces start code blocks and must be matched with a close brace
31 trytry is for executing a code block that may experience exceptions (errors)
32 {open braces start code blocks and must be matched with a close brace
33 faceValue=this assignment operator makes the left side equal to the right sideInteger.parseInt(name);
34 }close braces end code blocks and must match an earlier open brace
35 catchcatch means to handle an exception that may occur(NumberFormatException nfe)
36 {open braces start code blocks and must be matched with a close brace
37 ifif executes the next statement only if the condition in parenthesis evaluates to true(name.toLowerCase().startsWith("j"))
38 faceValue=this assignment operator makes the left side equal to the right side11;
39 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(name.toLowerCase().startsWith("q"))
40 faceValue=this assignment operator makes the left side equal to the right side12;
41 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(name.toLowerCase().startsWith("k"))
42 faceValue=this assignment operator makes the left side equal to the right side13;
43 elseelse is what happens when the if condition is false
44 faceValue=this assignment operator makes the left side equal to the right side1;
45 }close braces end code blocks and must match an earlier open brace
46 /*ifif executes the next statement only if the condition in parenthesis evaluates to true(name.equals("2"))
47 faceValue=this assignment operator makes the left side equal to the right side2;
48 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(name.equals("3"))
49 faceValue=this assignment operator makes the left side equal to the right side3;*/
50 }close braces end code blocks and must match an earlier open brace
51
52 publicpublic is used to indicate unrestricted access (any other class can have access) String toString()
53 {open braces start code blocks and must be matched with a close brace
54 ifif executes the next statement only if the condition in parenthesis evaluates to true(faceValue>=this evaluates to true if the left side is not less than the right side2 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) faceValue<=this evaluates to true if the left side is not more than the right side10)
55 returnreturn means to provide the result of the method and/or cease execution of the method immediately ""+adds two numbers together or concatenates Strings togetherfaceValue;
56 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(faceValue==this is the comparison operator which evaluates to true if both sides are the same1)
57 returnreturn means to provide the result of the method and/or cease execution of the method immediately "Ace";
58 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(faceValue==this is the comparison operator which evaluates to true if both sides are the same11)
59 returnreturn means to provide the result of the method and/or cease execution of the method immediately "Jack";
60 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(faceValue==this is the comparison operator which evaluates to true if both sides are the same12)
61 returnreturn means to provide the result of the method and/or cease execution of the method immediately "Queen";
62 elseelse is what happens when the if condition is false returnreturn means to provide the result of the method and/or cease execution of the method immediately "King";
63 }close braces end code blocks and must match an earlier open brace
64
65 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 compareTo(Rank arg0)
66 {open braces start code blocks and must be matched with a close brace
67 Wiki.out.println("comparing "+adds two numbers together or concatenates Strings togetherthisthis means the current object (the implicit parameter)+adds two numbers together or concatenates Strings together" to "+adds two numbers together or concatenates Strings togetherarg0);
68 returnreturn means to provide the result of the method and/or cease execution of the method immediately thisthis means the current object (the implicit parameter).faceValue-arg0.faceValue;
69 }close braces end code blocks and must match an earlier open brace
70 }close braces end code blocks and must match an earlier open brace
|
Download/View intermediate/Rank.java