Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need help please.

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!");

    }
    }
    }

  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default 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
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    13
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help please.

    O ok. I am sorry. Is it ok to post new threads on here if I have a new program?

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default 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.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code