Thanks for the help !!!! Could you help me with this last bit ? i cant do java! just confuses me. just due in tomorrow and ive got no clue what to do and i dont see my lectuer till next week. dont want to fail i was a late start to the college and misees a few weeks due to work issues.
Add a further method to your program which gives the user a hint as to whether the guess they made is close to the correct answer. The method signature is given below. The method should print "cold" if the users guess is 3 or more away from the correct answer. It should print "warm" if the guess if 2 away from the correct answer. It should print "hot" is the guess is only 1 away than the correct answer. Modify your program from (1) so that this method is called after every attempt by the user to guess the number.
public static String howClose(int userGuess, int randomNumber)
Heres what ive done so far with it where would i add the message ? and how would i fix the howClose Class?
PHP Code:
return match;
} //end Boolean
public static String howClose(int userGuess, int RandomNumber){
for (userGuess < 2 || RandomNumber > 2){
cold = true;
return cold;
if (userGuess < 2 || RandomNumber > 2)
warm = true;
return warm;
}
else {(userGuess < 1 || RandomNumber > 1)
hot = true;
return hot;
}
}
public static void main (String args[]) {
String userGuess;
int RandomNumber,userNumber;
String output="";
boolean match;
boolean hot,cold,warm;
// generate a random number between 1 and 10
RandomNumber = (int) (Math.random() * 9) + 1;
// Progam to run 3 Times before Exit
for (int counter = 0; counter <= 3; counter++) {
if (counter == 3) {
// If User is wrong 3 times then they are lost
output ="You have Lost Try Again The Random Number Was "+ RandomNumber;
// print message
JOptionPane.showMessageDialog(null, output, "Lost", JOptionPane.INFORMATION_MESSAGE);
}//End If
else{
// prompt user for Guess
userGuess = JOptionPane.showInputDialog("Please enter a Guess");
// convert string to integer
userNumber = Integer.parseInt(userGuess);
// You have Won Output
match = checkGuess(userNumber,RandomNumber);
if (match == true) {
// construct output
output = "You Have Won! "+RandomNumber;
break;
}//End If
}// End Else
} //End For
// print message
JOptionPane.showMessageDialog(null, output, "Win", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}//End Main
}
Social Networking Bookmarks