So I got this far and its terrible. I really don't know what to do. Can someone help me? I know there is alot of if statements and messed it up. I am using JOptionPane
I am trying to create a guessing game and these are all the rules to creating it.
Write a program that generates a random number between 1 and 10, then asks a player to guess your number. The player should be given three tries to guess your number.
Each time the player guesses, you should give them some feed back. Let them know if their guess was too high, or too low, or if they won the game!
When the player guess correctly the game is over, don't keep asking them to guess. And remember,after three wrong guesses, the computer wins!
Do NOT use a loop for this program.
Here is my program so far............................................... ......................
import javax.swing.JOptionPane;
public class GuessingGame {
public static void main (String [] args) {
int num1 = (int) (System.currentTimeMillis()%10);
String answerString = JOptionPane.showInputDialog(null,"Guess a number between 1 and 10");
int answer = Integer.parseInt(answerString);
//------------------------------------------------------------------------------------
{
if (answer > num1){
JOptionPane.showMessageDialog(null,"Your answer is too high");
String answerString1 = JOptionPane.showInputDialog(null,"Try again. Guess a number between 1 and 10");
answer = Integer.parseInt(answerString1);
}
else if (answer > num1){
JOptionPane.showMessageDialog(null,"Your answer is still too high");
String answerString2 = JOptionPane.showInputDialog(null,"Last chance. Guess a number between 1 and 10");
answer = Integer.parseInt(answerString2);
}
else if (answer == num1)
JOptionPane.showMessageDialog(null,"You Win!");
else
JOptionPane.showMessageDialog(null,"Computer Wins!");
}
//----------------------------------------------------------------------------------
{
if (answer < num1){
JOptionPane.showMessageDialog(null,"Your answer is too low");
String answerString3 = JOptionPane.showInputDialog(null,"Try again. Guess a number between 1 and 10");
answer = Integer.parseInt(answerString3);
}
else if (answer < num1){
JOptionPane.showMessageDialog(null,"Your answer is still too low");
String answerString4 = JOptionPane.showInputDialog(null,"Last chance. Guess a number between 1 and 10");
answer = Integer.parseInt(answerString4);
}
else if (answer == num1)
JOptionPane.showMessageDialog(null,"You Win!");
else
JOptionPane.showMessageDialog(null,"Computer Wins!");
}
}
}