|
001 importimport means to make the classes and/or packages available in this program java.util.*;
002 /**
003 * All about my classclass is a group of fields and methods used for making objects here.
004 * @authorthis is the Javadoc tag for documenting who created the source code Jam Jenkins
005 */
006 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 Guess
007 {open braces start code blocks and must be matched with a close brace
008 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer rightAnswer;
009 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer guessesLeft;
010 privateprivate is used to restrict access to the current class only intint is the type for whole numbers and it is short for integer response;
011
012 publicpublic is used to indicate unrestricted access (any other class can have access) Guess()
013 {open braces start code blocks and must be matched with a close brace
014 Random random=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Random();
015 rightAnswer=this assignment operator makes the left side equal to the right siderandom.nextInt(100)+adds two numbers together or concatenates Strings together1;
016 guessesLeft=this assignment operator makes the left side equal to the right side7;
017 response=this assignment operator makes the left side equal to the right side50;
018 }close braces end code blocks and must match an earlier open brace
019
020 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value setGuess(intint is the type for whole numbers and it is short for integer num)
021 {open braces start code blocks and must be matched with a close brace
022 ifif executes the next statement only if the condition in parenthesis evaluates to true(response!=this is the not equals operator which evaluates to true if both sides are differentrightAnswer &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 &&) guessesLeft>0)
023 {open braces start code blocks and must be matched with a close brace
024 response=this assignment operator makes the left side equal to the right sidenum;
025 }close braces end code blocks and must match an earlier open brace
026 }close braces end code blocks and must match an earlier open brace
027
028 publicpublic is used to indicate unrestricted access (any other class can have access) String getHint()
029 {open braces start code blocks and must be matched with a close brace
030 ifif executes the next statement only if the condition in parenthesis evaluates to true(guessesLeft<=this evaluates to true if the left side is not more than the right side1 &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 &&) response!=this is the not equals operator which evaluates to true if both sides are differentrightAnswer)
031 {open braces start code blocks and must be matched with a close brace
032 returnreturn means to provide the result of the method and/or cease execution of the method immediately ("Game over. Go home.");
033 }close braces end code blocks and must match an earlier open brace
034 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(response<rightAnswer)
035 {open braces start code blocks and must be matched with a close brace
036 returnreturn means to provide the result of the method and/or cease execution of the method immediately ("Too low. Guess higher.");
037 }close braces end code blocks and must match an earlier open brace
038 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(response>rightAnswer)
039 {open braces start code blocks and must be matched with a close brace
040 returnreturn means to provide the result of the method and/or cease execution of the method immediately ("Too high. Guess lower.");
041 }close braces end code blocks and must match an earlier open brace
042 elseelse is what happens when the if condition is false// if(response==Answer)
043 {open braces start code blocks and must be matched with a close brace
044 ifif executes the next statement only if the condition in parenthesis evaluates to true(guessesLeft>6)
045 {open braces start code blocks and must be matched with a close brace
046 returnreturn means to provide the result of the method and/or cease execution of the method immediately ("You lucky duck!");
047 }close braces end code blocks and must match an earlier open brace
048 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(guessesLeft>5)
049 {open braces start code blocks and must be matched with a close brace
050 returnreturn means to provide the result of the method and/or cease execution of the method immediately ("You're super genius");
051 }close braces end code blocks and must match an earlier open brace
052 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(guessesLeft>4)
053 {open braces start code blocks and must be matched with a close brace
054 returnreturn means to provide the result of the method and/or cease execution of the method immediately ("You're a genius!");
055 }close braces end code blocks and must match an earlier open brace
056 elseelse is what happens when the if condition is false
057 {open braces start code blocks and must be matched with a close brace
058 returnreturn means to provide the result of the method and/or cease execution of the method immediately ("Congratulations");
059 }close braces end code blocks and must match an earlier open brace
060 }close braces end code blocks and must match an earlier open brace
061 }close braces end code blocks and must match an earlier open brace
062
063 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value requestNumber()
064 {open braces start code blocks and must be matched with a close brace
065 ifif executes the next statement only if the condition in parenthesis evaluates to true(response!=this is the not equals operator which evaluates to true if both sides are differentrightAnswer &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 &&) guessesLeft>0)
066 {open braces start code blocks and must be matched with a close brace
067 Wiki.out.println("What number would you like to guess?");
068 Scanner scanner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Scanner(Wiki.in);
069 response=this assignment operator makes the left side equal to the right sidescanner.nextInt();
070 }close braces end code blocks and must match an earlier open brace
071 }close braces end code blocks and must match an earlier open brace
072
073 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value giveHint()
074 {open braces start code blocks and must be matched with a close brace
075 ifif executes the next statement only if the condition in parenthesis evaluates to true(guessesLeft<=this evaluates to true if the left side is not more than the right side1 &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 &&) response!=this is the not equals operator which evaluates to true if both sides are differentrightAnswer)
076 {open braces start code blocks and must be matched with a close brace
077 Wiki.out.println("Game over. Go home.");
078 }close braces end code blocks and must match an earlier open brace
079 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(response<rightAnswer)
080 {open braces start code blocks and must be matched with a close brace
081 Wiki.out.println("Too low. Guess higher.");
082 }close braces end code blocks and must match an earlier open brace
083 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(response>rightAnswer)
084 {open braces start code blocks and must be matched with a close brace
085 Wiki.out.println("Too high. Guess lower.");
086 }close braces end code blocks and must match an earlier open brace
087 elseelse is what happens when the if condition is false// if(response==Answer)
088 {open braces start code blocks and must be matched with a close brace
089 ifif executes the next statement only if the condition in parenthesis evaluates to true(guessesLeft>6)
090 {open braces start code blocks and must be matched with a close brace
091 Wiki.out.println("You lucky duck!");
092 }close braces end code blocks and must match an earlier open brace
093 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(guessesLeft>5)
094 {open braces start code blocks and must be matched with a close brace
095 Wiki.out.println("You're super genius");
096 }close braces end code blocks and must match an earlier open brace
097 elseelse is what happens when the if condition is false ifif executes the next statement only if the condition in parenthesis evaluates to true(guessesLeft>4)
098 {open braces start code blocks and must be matched with a close brace
099 Wiki.out.println("You're a genius!");
100 }close braces end code blocks and must match an earlier open brace
101 elseelse is what happens when the if condition is false
102 {open braces start code blocks and must be matched with a close brace
103 Wiki.out.println("Congratulations");
104 }close braces end code blocks and must match an earlier open brace
105 }close braces end code blocks and must match an earlier open brace
106 }close braces end code blocks and must match an earlier open brace
107
108 publicpublic is used to indicate unrestricted access (any other class can have access) voidvoid means the method does not return a value remaining()
109 {open braces start code blocks and must be matched with a close brace
110 ifif executes the next statement only if the condition in parenthesis evaluates to true(response!=this is the not equals operator which evaluates to true if both sides are differentrightAnswer)
111 {open braces start code blocks and must be matched with a close brace
112 guessesLeft--this is the decrement operator, which decreases the variable by 1;//guessesLeft=guessesLeft-1;
113 Wiki.out.println("You have "+adds two numbers together or concatenates Strings togetherguessesLeft+adds two numbers together or concatenates Strings together" guesses left.");
114 }close braces end code blocks and must match an earlier open brace
115 }close braces end code blocks and must match an earlier open brace
116
117 publicpublic is used to indicate unrestricted access (any other class can have access) booleanboolean is a type that is either true or false gameIsOver()
118 {open braces start code blocks and must be matched with a close brace
119 ifif executes the next statement only if the condition in parenthesis evaluates to true(response==this is the comparison operator which evaluates to true if both sides are the samerightAnswer ||this is boolean or, meaning if either or both are true then the result is true guessesLeft==this is the comparison operator which evaluates to true if both sides are the same0)
120 {open braces start code blocks and must be matched with a close brace
121 returnreturn means to provide the result of the method and/or cease execution of the method immediately truetrue is the boolean value that is the opposite of false;
122 }close braces end code blocks and must match an earlier open brace
123 elseelse is what happens when the if condition is false
124 {open braces start code blocks and must be matched with a close brace
125 returnreturn means to provide the result of the method and/or cease execution of the method immediately falsefalse is a value for the boolean type and means not true;
126 }close braces end code blocks and must match an earlier open brace
127 }close braces end code blocks and must match an earlier open brace
128 }close braces end code blocks and must match an earlier open brace
|