From ggc
|
01 packagepackage is used to name the directory or folder a class is in jam;
02
03 importimport means to make the classes and/or packages available in this program wiki.Wiki;
04 /**
05 * All about my classclass is a group of fields and methods used for making objects here.
06 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
07 */
08 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 HangmanModel
09 {open braces start code blocks and must be matched with a close brace
10 privateprivate is used to restrict access to the current class only String phrase;
11 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer wrongGuesses;
12 privateprivate is used to restrict access to the current class only String blanks;
13
14 publicpublic is used to indicate unrestricted access (any other class can have access) HangmanModel()
15 {open braces start code blocks and must be matched with a close brace
16 phrase=this assignment operator makes the left side equal to the right side"";
17 wrongGuesses=this assignment operator makes the left side equal to the right side0;
18 blanks=this assignment operator makes the left side equal to the right side"";
19 }close braces end code blocks and must match an earlier open brace
20
21 publicpublic is used to indicate unrestricted access (any other class can have access) HangmanModel(String answer)
22 {open braces start code blocks and must be matched with a close brace
23 //ignoring what information is supplied:
24 //answer="How is hangman?";
25 phrase=this assignment operator makes the left side equal to the right sideanswer;
26 wrongGuesses=this assignment operator makes the left side equal to the right side0;
27 blanks=this assignment operator makes the left side equal to the right sidephrase.replaceAll("[a-zA-Z]", "*");
28 }close braces end code blocks and must match an earlier open brace
29
30 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setAnswer(String answer)
31 {open braces start code blocks and must be matched with a close brace
32 phrase=this assignment operator makes the left side equal to the right sideanswer;
33 }close braces end code blocks and must match an earlier open brace
34
35 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false guess(charchar is the type for a single letter or symbol and it is short for character letter)
36 {open braces start code blocks and must be matched with a close brace
37 booleanboolean is a type that is either true or false correct=this assignment operator makes the left side equal to the right sidefalsefalse is a value for the boolean type and means not true;
38 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<phrase.length(); i++this is the increment operator, which increases the variable by 1)
39 {open braces start code blocks and must be matched with a close brace
40 charchar is the type for a single letter or symbol and it is short for character one=this assignment operator makes the left side equal to the right sidephrase.toLowerCase().charAt(i);
41 ifif executes the next statement only if the condition in parenthesis evaluates to true(one==this is the comparison operator which evaluates to true if both sides are the sameletter)
42 {open braces start code blocks and must be matched with a close brace
43 correct=this assignment operator makes the left side equal to the right sidetruetrue is the boolean value that is the opposite of false;
44 String firstPart=this assignment operator makes the left side equal to the right side"";
45 String lastPart=this assignment operator makes the left side equal to the right side"";
46 firstPart=this assignment operator makes the left side equal to the right sideblanks.substring(0, i);
47 ifif executes the next statement only if the condition in parenthesis evaluates to true(i+adds two numbers together or concatenates Strings together1<phrase.length())
48 lastPart=this assignment operator makes the left side equal to the right sideblanks.substring(i+adds two numbers together or concatenates Strings together1);
49 blanks=this assignment operator makes the left side equal to the right sidefirstPart+adds two numbers together or concatenates Strings togetherphrase.charAt(i)+adds two numbers together or concatenates Strings togetherlastPart;
50 }close braces end code blocks and must match an earlier open brace
51 }close braces end code blocks and must match an earlier open brace
52 ifif executes the next statement only if the condition in parenthesis evaluates to true(!this is the not operator, which changes true to false and false to truecorrect)
53 wrongGuesses++this is the increment operator, which increases the variable by 1;
54 returnreturn means to provide the result of the method and/or cease execution of the method immediately correct;
55 }close braces end code blocks and must match an earlier open brace
56
57 publicpublic is used to indicate unrestricted access (any other class can have access) String getRemaining()
58 {open braces start code blocks and must be matched with a close brace
59 returnreturn means to provide the result of the method and/or cease execution of the method immediately blanks;
60 }close braces end code blocks and must match an earlier open brace
61
62 publicpublic is used to indicate unrestricted access (any other class can have access) String getAnswer()
63 {open braces start code blocks and must be matched with a close brace
64 returnreturn means to provide the result of the method and/or cease execution of the method immediately phrase;
65 }close braces end code blocks and must match an earlier open brace
66
67 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 getNumberOfWrongGuesses()
68 {open braces start code blocks and must be matched with a close brace
69 returnreturn means to provide the result of the method and/or cease execution of the method immediately wrongGuesses;
70 }close braces end code blocks and must match an earlier open brace
71 }close braces end code blocks and must match an earlier open brace
|
Download/View jam/HangmanModel.java