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 2 of 2

Thread: Need help with my java code! [URGENT]

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help with my java code! [URGENT]

    import javax.swing.*;
    class IndependentProject{
    public static void main(String str[]){
    int score=0;
    int chance1=0;
    int rymeagain1=0;
    int guess2=0;
    int a=(int)(1+Math.random()*3);	
     
    do{
    JOptionPane.showMessageDialog(null,"Welcome to ANIMALS AT THE BARN!");
    System.out.println("Welcome to ANIMALS AT THE BARN!");
     
     
     
     
     
    String input1 =JOptionPane.showInputDialog(null,"How many animals are in the barn? Guess a number between 1-3");
    int  guess = Integer.parseInt(input1);
     
    if(guess==a){
    System.out.println(" ");
    System.out.println("Good job, you got that correct there are " +a+ " animals in the barn, you gain +1 score");
    JOptionPane.showMessageDialog(null,"Good job, you got that correct there are " +a+ " animals in the barn, you gain +1 score");
    score=score+1;
    }
     
    else{
    JOptionPane.showMessageDialog(null, "Incorrect, You get to pick another number");
    String input2=JOptionPane.showInputDialog("Do you want to pick another number??\nYes \nNo");
    String chance=input2;
    if(chance.equalsIgnoreCase("yes")){
    chance1=1;	
     
    }
     
    //if(guessagain==b){
    //System.out.println(" ");
    //System.out.println("Good job, you got that correct there are " +b+ " animals in the barn, you gain +1 score");
    //JOptionPane.showMessageDialog(null,"Good job, you got that correct there are " +b+ " animals in the barn, you gain +1 score");
    //score=score+1;
     
    }
     
     
    //else{
     
    //JOptionPane.showMessageDialog(null, "Incorrect, GAME OVER!");
    //guessagain1=0;
    //break;
    //}
     
     
    		 		 	//if(guessagain1==0) {
     
    		 		 		//JOptionPane.showMessageDialog(null,"Thanks for playing Animals at the barn!! You left the game with "+score+" points!!");
    		 		 		//System.out.println("Thanks for playing Animals at the barn!! You left the game with "+score+" points!!");
    		 		 	//	break;
     
    //}
     
     
     
     
    do{
     
    JOptionPane.showMessageDialog(null,"There are " +a+ " animals, find the two names that rhyme together from the list of "+a+" animals in the barn");
    if(a==1){
    JOptionPane.showMessageDialog(null,"There is only 1 animal in this barn, you don't have to find two names that rhyme! You gain +1 score automatically!");
    score=score+1;
    }
    else if(a==2){
    String input3=JOptionPane.showInputDialog("The names of the animals are \nBetty, \nJohn, \nTeddy \nWhich of these two names rhyme? Enter the first letter of the two names, example ET(MUST BE IN ORDER FROM TOP TO BOTTOM!!)");
    String two=input3;
    if(two.equalsIgnoreCase("BT"))
    JOptionPane.showMessageDialog(null,"CORRECT, Betty & Teddy Rhyme! You gain +1 score!!");
    score=score+1;
     
    }
    else if(a==3){
    String input4=JOptionPane.showInputDialog("The names of the animals are \nJohn, \nSean, \nRon, \nBOB \nWhich of these three names rhyme? Enter the first letter of the three names, example ETY(MUST BE IN ORDER FROM TOP TO BOTTOM!!)");	
    String three=input4;
    if(three.equalsIgnoreCase("JSR"))
    JOptionPane.showMessageDialog(null,"CORRECT, John & Sean & Ron Rhyme! You gain +1 score!!");
    score=score+1;
    }
     
    else{
    JOptionPane.showMessageDialog(null, "You did not input the names correct, you get to try again Hint: Make sure you entered the input in the correct format & order, and make sure the the names rhyme");
    String input5=JOptionPane.showInputDialog("Do you want to try rhyming the numbers again??");
    String rymeagain=input5;	
    rymeagain1=1;
    }
    }while(rymeagain1==1); // Lets you rhyme the numbers again
     
    } while(chance1==1);// plays again if the number from 1-3 is incorrect
     
     
    } //(String str[]){
    }// class IndependentProject{


    Ok so the problem is,

    The program guesses a number between 1-3, and if the user guesses it right it moves onto the next step.. (That works fine)

    But if the user gets it incorrect, the program is supposed to ask if the user wants to try picking again, (That works fine)
    But when the user enters yes, it just moves onto the next step without going through the loop..

    Can fix my problem?? I posted my code thanks!

    --- Update ---

    Nvm! Got this part, will post if have different questions.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,434
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: Need help with my java code! [URGENT]

    Be sure to properly format any code you post. This code is poorly formatted making it very hard to read.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. URGENT: Please help me with my code!
    By Snoopchicken in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 18th, 2012, 05:21 PM
  2. Need urgent help regarding java word wrap function.. URGENT
    By coldice in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 16th, 2011, 05:43 AM
  3. Need help with this code urgent please, i appreciate it.
    By joelmeler in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 30th, 2011, 09:11 PM
  4. URGENT Need help with code for billing
    By ab3lr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 13th, 2011, 10:44 AM
  5. Urgent code needed
    By subhvi in forum AWT / Java Swing
    Replies: 4
    Last Post: August 27th, 2009, 12:55 AM