-
Need help please.
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!");
}
}
}
-
Re: Need help please.
Please don't open new threads when you already have ones open on the same topic.
Such behaviour goes against forum rules.
http://www.javaprogrammingforums.com...ease-%3Dd.html
-
Re: Need help please.
O ok. I am sorry. Is it ok to post new threads on here if I have a new program?
-
Re: Need help please.
If you're working on a totally different project, yeah ofcourse you can start a new thread.
It's just to nobody's interest when you post the exact same issues in two threads, it can cause many issues including wasting peoples time by replying to 1 thread when It's been solved in another.