Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

I need some help will someone help plz

java

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 divinity03

divinity03

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 18 November 2015 - 02:20 AM

hi everyone

 

i am building a java program. it is a multiple choice maths game program. the game supposed to random numbers to add, subtract and divide. it consists of 4 questions, question from 1 through 4 and for each questions in the first round two random numbers must be generated. the first random number must between 1 -25 and the second from 1 -9;

the game must generate two multiple choice options with each option should contain a character and a number one of which should be the correct answer and a wrong answer and the player has the choice to choose to enter the character which correspond with the correct answer, right

 

 

my problem is: i manage to get the part where it generate the questions with also the character and the number (something like this

melissa what is 11 + 5
A:16
B:16
b
it generating two same answer when it should be generate two different answer, one should be the correct ans and the other one the wrong one.
 
the game loop and keep jumping one block of code. I just cant seem to get it right the way it supposed to be. here is my code and output. I have implementd a block of code where in case the user enters the wrong ans so that it can give them another chance to answer corrected. 
 char choice;
       
       String username, welcomemsg, rulesofgme;//this is entering the username and the welcome msg
       
       int level, userage;
       int sumpts =0;
       int totalpts_username =0;
       
       int incorrect = 0; //to hold the number of incorrect answers
       int correct = 0; // to hold the number of correct answers
       int answer = 0;// this is to hold the number of correct and incorrect answer
       
       //initializing the variables
        System.out.println("Welcome to Aunty Luz's Multiple Choice Math Game");
        System.out.println("Rules of the Game");
        System.out.println("The game consist of 3 rounds up to level 5");
        System.out.println("The age limit is from 8 - 13 "+ " no younger or older");
        System.out.println("Each player has 3 chances to answer correctly");
        System.out.println("Each correct answer is reward with points");
        System.out.println("Every incorrect answer will result point being taken away");
        System.out.println("okay, so I hope that I have made myself perfectly clear");
        
        System.out.println("*+*+*+*+*+*+*+welcome to round 1*+*+*+*+*+*+*+*");
        
        System.out.println("Hi there, can you tell me your name please");
        username = userinput.next();
        System.out.println(username+" How old are you");
        userage = userinput.nextInt();
        //seeking to get the username and userage
        
        //this while loop is used to check if user enter the correct age
        if(userage < 8 || userage > 13)
        {
           System.out.println("exist game");//this is where if the user enter the incorrect age, the game is to exist
        }
        else
        {
            System.out.println("boooooom!!! an iz zat "+ " you can play this game");
            //this is where the correct age is entered by the user when the user realized the game has exit when the incorrect age is entered
        }
        
        int random, random1;
        int i = 1;
        
        while(i < 4)//this while loop is used as to 
        {
            random = randobj.nextInt(25)+ 1;//this is to generate number from 1-25
            random1 = randobj.nextInt(9)+ 1;//this is used to generate numbers from 1-9
            int sum = 0;
            int sum1 =0;
          
            System.out.println(username+" you are on round 1, level, "+ "can you please enter the letter which represent the correct answer");
            System.out.println(username+" what is "+random+" + "+random1);
            
            sum = random + random1;//this display the answer
            sum1 = random + random1 + random1;
            
            System.out.println("A:"+sum);
            System.out.println("B:"+sum);
            choice = userinput.next().charAt(0);
            
        if(choice == 'A' || choice == 'a')//this if statement meant that it doesnt matter which character the user entered
        {
            System.out.println(username+" that is the correct answer:-) "+ " you earned yourself 350 point "+ " good job, keep up the good work");
            sumpts = +350;
            totalpts_username++;
                
        }
        else if(choice == 'B' || choice == 'b')
        {
            System.out.println(username+" that answer is incorrect "+ " you lose 175 points "+ " better luck next time");
            sumpts = -175;
            totalpts_username++;the compileer jump from this block of codes to the block of codes 
below
            i++;
            
        }
        while(choice != 'A' || choice != 'B')//this while loop is used to give the user another chance
        {
            System.out.println(username+ " you are given another chance "+ " make the most of it");
            System.out.println("A"+sum);
            System.out.println("B"+sum);
            choice = userinput.next().charAt(0);
            break;
        }
        
            System.out.println("+*+*+*+*+*+*+*+*welcome to round 2*+*+*+*+*+*+*+*+*+*+");
            
        while(i < 4)
        {
            random = randobj.nextInt(25)+1;
            random1 = randobj.nextInt(9)+1;
            sum = 0;
            sum1= 0;
            
            System.out.println(username+" you are on round 2, level 5 "+ " you are hereby required to entered the letter which represent the correct answer");
            System.out.println(username+" what is "+ random+ " - "+ random1);
            
            System.out.println("A:"+sum);
            System.out.println("B:"+sum);
            choice = userinput.next().charAt(0);
            
        if(choice == 'A' || choice == 'a')
        {
            System.out.println("correct is right "+username+ "you earned yourself 350 point "+ " well done!! keep up the good work, my little friend");
            sumpts = + 350;
            totalpts_username++;
            i++;
        }
        else if(choice == 'B' || choice == 'b')
        {
            System.out.println("that is not correct "+username+ " do you want some help "+ " better luck next time " + " you just lose 175 points for that");
            sumpts = - 175;
            totalpts_username++;
            break;
            
        }
        }
            here is the output
run:
Welcome to Aunty Luz's Multiple Choice Math Game
Rules of the Game
The game consist of 3 rounds up to level 5
The age limit is from 8 - 13  no younger or older
Each player has 3 chances to answer correctly
Each correct answer is reward with points
Every incorrect answer will result point being taken away
okay, so I hope that I have made myself perfectly clear
*+*+*+*+*+*+*+welcome to round 1*+*+*+*+*+*+*+*
Hi there, can you tell me your name please
melissa
melissa How old are you
10
boooooom!!! an iz zat  you can play this game
melissa you are on round 1, level, can you please enter the letter which represent the correct answer
melissa what is 11 + 5
A:16
B:16
b
melissa that answer is incorrect  you lose 175 points  better luck next time
melissa you are given another chance  make the most of it
A16
B16
b
+*+*+*+*+*+*+*+*welcome to round 2*+*+*+*+*+*+*+*+*+*+
melissa you are on round 2, level 5  you are hereby required to entered the letter which represent the correct answer
melissa what is 16 - 6
A:0
B:0
b
that is not correct melissa do you want some help  better luck next time  you just lose 175 points for that
melissa you are on round 1, level, can you please enter the letter which represent the correct answer
melissa what is 12 + 1
A:13
B:13
a
melissa that is the correct answer:-)  you earned yourself 350 point  good job, keep up the good work
melissa you are given another chance  make the most of it
A13
B13
BUILD STOPPED (total time: 49 seconds)

whenever i delete the block of codes in the while loop where it say: while(choice !='a' || choice !=b, it would go into an infinite loop and it only break out of it whenever the user enters the wrong answer. 

 

can someone please help 

many thanks in advance

 



#2 divinity03

divinity03

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 18 November 2015 - 10:56 AM

 if(userage < 8 || userage > 13)
        {
            System.out.println("exit"); 
        }
        else
        {
            System.out.println("yesss!! you can play");
        }
output
Welcome to Aunty Luz's Multiple Choice Math Game
Rules of the Game
The game consist of 3 rounds up to level 5
The age limit is from 8 - 13  no younger or older
Each player has 3 chances to answer correctly
Each correct answer is reward with points
Every incorrect answer will result point being taken away
okay, so I hope that I have made myself perfectly clear
*+*+*+*+*+*+*+welcome to round 1*+*+*+*+*+*+*+*
Hi there, can you tell me your name please
kevon
kevon How old are you
4
exit
kevon you are on round 1, level, can you please enter the letter which represent the correct answer
kevon what is 16 + 3
A:19
B:19

in the first block of codes where it is asking the user to input their age and if they entered the wrong age the game supposed to exit the game but still when the user enter the wrong age, the game continues instead of existing.

 

can someone tell me what to do and how to fix it



#3 SteveJoe

SteveJoe

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 19 November 2015 - 11:06 PM

This will take quite a bit of time and I might not be able to debug it myself. So I will take this problem to my teacher and then let you know. To be honest, I might take upto 2 days as I am currently busy with one of my android project.

#4 divinity03

divinity03

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 20 November 2015 - 11:05 AM

here is a revised version of the game. i am having problem with it on what I said above among other. i  have to get the program to generate random numbers to ask 4 question based on addition, subtraction and division, the user has 4 chances so i have to created an if statement or while loop so that it can iterate to where the user has a chance to re-enter there answer. it has 3 game round with 6 level. 

char choice;
       String username,welcomemsg, rulesofgme;//this is entering the username and the welcome msg
       int level, userage; 
       
       int sumpts =0;
       int totalpts_username =0;
       int chances = 0;
       
       int incorrect = 0; //to hold the number of incorrect answers
       int correct = 0; // to hold the number of correct answers
       int answer = 0;// this is to hold the number of correct and incorrect answer
       
       
       
       //initializing the variable that will be used during the course of the game
       
        System.out.println("Welcome to Aunty Luz's Multiple Choice Math Game");
        System.out.println("The game consist of 3 round with 6 level");
        System.out.println("The age limit is 8 - 13 years ");
        System.out.println("A player wins the game if all questions are answerred correctly");
        System.out.println("The player loses the game if they run out of chances");
        System.out.println("Each player has 4 chances");
        System.out.println("Each correct answer is rewarded with a maximum of 350 points");
        System.out.println("Each incorrect answer will lose half of the alloted point given ");
        System.out.println("A report is submitted at the end of the game");
        System.out.println("A player only win the game if all 10 question are answered correctly");
        System.out.println("A player loses the game if the age is entered incorrectly or if the player ran out of the chances given");
        System.out.println("okay students, I hope that I have made myself very clear");
        //input the rules and regulation of the game 
        
       
        System.out.println("+*+*+*+*+*+*+*+*+welcome to game 1+*+*+*+*+*+*+*+");
        
        
        System.out.println("Hello there, what is your name");
        username = userinput.next();
        System.out.println(username+" you have a very unique name my dear");
        System.out.println("What is your age "+ username);
        userage = userinput.nextInt();
        System.out.println("hmmm nice age "+ username);
        //asking for the user's name and age
        
        
        while(userage >= 8 && userage <= 13)
        {
         
        //this while loop is used to check if user enter the correct age
        if(userage >=8 && userage <= 13)
        {
            //begin game 
            
            int random, random1;
            int i = 1;
            int irand1 = 5;
            int irand2 = 7;
            int sum = irand1 + irand2;
            
        
        while(i < 4)//this while loop is used as to 
        {
            random = randobj.nextInt(25)+ 1;//this is to generate number from 1-25
            random1 = randobj.nextInt(9)+ 1;//this is used to generate numbers from 1-9
            
            sum = 0;
            int sum1 =0;
          
            System.out.println(username+" you are on round 1, level, "+ "can you please enter the letter which represent the correct answer");
            System.out.println(username+" what is "+irand1+" + "+irand2+ "? ", ""+sum, ""+ (sum + difference));
            
            sum = irand1 + irand2;//this display the answer
            /*if( )*/
            {
            }
            System.out.println("A:"+sum);
            System.out.println("B:"+sum);
            choice = userinput.next().charAt(0);
            
        if(choice == 'A' || choice == 'a')//this if statement meant that it doesn’t matter which character the user entered
        {
            System.out.println(username+" that is the correct answer:-) "+ " you earned yourself 350 point "+ " good job, keep up the good work");
            sumpts = +350;
            totalpts_username++;
            chances++;
                
        }
        else if(choice == 'B' || choice == 'b')
        {
            System.out.println(username+" that answer is incorrect "+ " you lose 175 points "+ " better luck next time");
            sumpts = -175;
            totalpts_username++;
            chances++;
            i++;
            
        }
        while(choice != 'A' || choice != 'B')//this while loop is used to give the user another chance
        {
            System.out.println(username+ " you are given another chance "+ " make the most of it");
            System.out.println(username+" what is "+ irand1+ " + "+ irand2+ "?, "+sum, ""+ (sum + difference));
            System.out.println("A"+sum);
            System.out.println("B"+sum);
            choice = userinput.next().charAt(0);
            break;
        }
        
         
        while(i < 4)
        {
             random = randobj.nextInt(25)+ 1;//this is to generate number from 1-25
             random1 = randobj.nextInt(9)+ 1;//this is used to generate numbers from 1-9
            
             sum = 0;
             sum1 =0;
          
             System.out.println(username+" you are on round 1, leve 2, "+ "can you please enter the letter which represent the correct answer");
             System.out.println(username+" what is "+irand1+" + "+irand2+ "? ", ""+sum, ""+ (sum + difference));
            
            sum = irand1 + irand2;//this display the answer
            /*if( )*/
        {
        }
            System.out.println("A:"+sum);
            System.out.println("B:"+sum);
            choice = userinput.next().charAt(0);
            
        if(choice == 'A' || choice == 'a')
        {
            System.out.println(username+" that answer is quite correct:-)"+ " keep up the good work");
            sumpts = +352;
            totalpts_username++;
            chances++;
        }
        else if(choice == 'B' || choice == 'b')
        {
            System.out.println(username+" that is incorrect "+ " please try again");
            sumpts = -175;
            totalpts_username++;
            chances++;
            i++;
        }
        if(choice != 'A' || choice != 'B')//this if statement is checking to see if the answer entered is not equal to their answers entered
        {
            System.out.println(username+" plz try harder this time");
            System.out.println(username+" what is "+ irand1+ " + "+irand2+ "?", ""+ sum, ""+ (sum + difference));
            System.out.println("A:"+sum);
            System.out.println("B:"+sum);
            choice = userinput.next().charAt(0);
            //this here is given the user another chance to answer the question correctly
        }
         else   
        {
            System.out.println(username+"you lose the game");// this is indicating that the user has exhausted their chances
            
        }
            System.out.println("exit game");//this is where is the game will end if the user uses up all their chances.
              
        }
            
        
         System.out.println("+*+*+*+*+*+*+*+*welcome to round 2*+*+*+*+*+*+*+*+*+*+");
            
        while(i < 4)
        {
            random = randobj.nextInt(25)+1;
            random1 = randobj.nextInt(9)+1;
            sum = 0;
            sum1= 0;
            
            System.out.println(username+" you are on round 2, level 5 "+ " you are hereby required to entered the letter which represent the correct answer");
            System.out.println(username+" what is "+ random+ " - "+ random1);
            
            System.out.println("A:"+sum);
            System.out.println("B:"+sum);
            choice = userinput.next().charAt(0);
            
        if(choice == 'A' || choice == 'a')//this is used to say that it doesnt matter which character  is used,the answer will still display
        {
            System.out.println("correct is right "+username+ " you earned yourself 350 point "+ " well done!! keep up the good work, my little friend");
            sumpts = + 350;
            totalpts_username++;
            chances++;
            i++;
        }
        else if(choice == 'B' || choice == 'b')//the user have to opportunity to enter either of the two character the answer would remain the same
        {
            System.out.println("that is not correct "+username+ " do you want some help "+ " better luck next time " + " you just lose 175 points for that");
            sumpts = - 175;
            totalpts_username++;
            chances++;
            break;
        }
        if(choice != 'A' || choice == 'B')
        {
            System.out.println(username+" you need to try again ");//giving the user another chance to input the correct answer
            System.out.println("A:"+sum);
            System.out.println("B:"+sum);
            choice = userinput.next().charAt(0);
        }
        }//while loop end

            
          
            
            
            
        }
        }
        else
        {
            
              System.out.println("Sorry your age is invalid");
            
        }
        

the problem i am having is that i need to get the program to be like this

system.out.println(username+ "how much is "+ num1+ "+" +num2+ "? 

like this ah mean how much is 16+3 equals

A:19
B:13

they will have to choose either A or B as the answer. it is a multiple choice game

i need to add scores to the game and how to total the score they make 

can u show me what to do.