This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2016/4/14

why is skipping the whole of the first round

divinity divinity

2016/4/14

#
hi danpost how are you. hope you are in the best of health. well you know i am building my final assignment for programming which is a multiple choice math game this is some of the specification of the game 1. the game supposed to randomized (if you understand what ah mean by randomized) 2 when playing the game, and if the user entered the wrong answered two three times it is supposed to stay on the same level and same round and same number until the user get it right. 3 it should end when the user ran out of chances 4 i have implemented an if and else statement if the game. i put at after the for loop and above the random numbers and now it is just jumping and skipping the whole of round 1 and going on to round two and three. dont know what is the course of that. how can i get it to work for both round 1, 2 and 3. can u look through my codes and tell me where it the logical error because i kno it is there. any help will be greatly appreciated.
if(playerage < 8 )
        {
            System.out.println(playername+" you are too young for this game");
            System.exit(0);
        }
        else if( playerage > 13)
        {
            System.out.println(playername+" you are to old for this game  ");
            System.exit(0);
        }
        else
        {
            System.out.println(playername+" kapow!!!! come let us have fun playing");
        }
        System.out.println("                                 ");
        
        System.out.println("***************round 1*********************************");
        
        System.out.println("                                          ");
        
        
        
        
        for(i = 1; i<=4; i++)
        {
            if(uSelect == 1) (this is the if else am talking about, if I removed it the code would work, something making it not to work
            {
                //getting the random numbers
                intvalue = 1 + randobj.nextInt(25);
                intvalue = 2 + randobj.nextInt(8);
                correct_ans = intvalue + intvalue2;
                incorrect_ans = 75 + randobj.nextInt(75);
                
                System.out.println(playername+" you are starting on round 1 "+ " level "+ i + "question "+ i +" match the letter with the correct answer");
                System.out.println(playername+" please add "+intvalue + " + "+ intvalue);
                
                //implementing the letter for the correct answer
                System.out.println("A:"+correct_ans);
                System.out.println("B:"+incorrect_ans);
                uSelect = reader.next().charAt(0);
                
                if(uSelect == 'A' || uSelect == 'b')
                {
                    System.out.println(playername+" excellent and brilliant kiddo!!! answer is correct, keep up the good work");
                    score += score + 350;
                    System.out.println("round 1");
                    System.out.println("level "+ i);
                    System.out.println("question "+ i);
                    totalscore += score;
                    System.out.println("total score is: "+ totalscore);
                    count++;
                    wrong = wrongcount + i;
                }
                else if(uSelect == 'B' || uSelect == 'b')
                {
                    System.out.println(playername+" chittychitty bangbang!!!!  answer is wrong, try again");
                    score -= score - 175;
                    System.out.println("round: 1");
                    System.out.println("level: "+ i);
                    System.out.println("question: "+ i);
                    totalscore -=score;
                    System.out.println("total score "+ totalscore);
                    count++;
                    wrong = wrongcount + i;
                }
                else if(uSelect == 2)
                {
                    if(wrong > i)
                    {
                        System.out.println(playername+" you are still on round 1"+ "level "+ i +" question "+ i + " match the letter with the correct  answer");
                        System.out.println(playername+" please add "+ intvalue + " + "+ intvalue);
                        
                        //get the right letter to correct answer
                        System.out.println("A: "+correct_ans);
                        System.out.println("B: "+incorrect_ans);
                        uSelect = reader.next().charAt(0);
                        
                        if(uSelect == 'A' || uSelect == 'b')
                        {
                            System.out.println(playername+" brillian kiddoo!!! yesss correct is right ");
                            score += score + 350;
                            System.out.println("round 1");
                            System.out.println("level "+ i);
                            System.out.println("question: "+ i);
                            totalscore += score;
                            System.out.println("total score "+totalscore);
                            count++;
                        }
                        else if(uSelect == 'B' || uSelect == 'b')
                        {
                            System.out.println(playername+" awwww come one now, kiddooo that is so wrong");
                            score -= score - 175;
                            System.out.println("round 1");
                            System.out.println("level:"+ i);
                            System.out.println("question "+ i);
                            totalscore -=score;
                            System.out.println("total score is: "+totalscore);
                            count++;
                            wrong = wrongcount + i;
                        }
                        
                        
                    }
                }
                
            }
        }
danpost danpost

2016/4/14

#
There has got to be more to this class than that. I do not see (1) imports, (2) class declaration line, (3) fields, or (4) a method declaration line.
divinity divinity

2016/4/14

#
class declaration line, imports, fields or method declaration line, ah doh understand what you mean by that can u explain each line
danpost danpost

2016/4/15

#
divinity wrote...
class declaration line, imports, fields or method declaration line, ah doh understand what you mean by that can u explain each line
Just copy/paste the entire class here (use Ctrl-A to 'select all').
divinity divinity

2016/4/15

#
hi danpost is this what you are talking about
package luanataylor_multiplicatiochoicegame;

import java.util.Scanner;
import java.util.Random;
 
public class Luanataylor_multiplicatiochoicegame 
{

    
    public static void main(String[] args) 
    {
        Scanner reader = new Scanner(System.in);
        
        Random randobj = new Random();
danpost danpost

2016/4/15

#
divinity wrote...
hi danpost is this what you are talking about < Code Omitted >
Yes. Class description is line 6. Imports are lines 3 and 4. Fields (none shown) -- but variables are lines 12 and 14. Method declaration is line 10. This still cannot be all of it as you are using a variable called 'uSelect' which I do not see defined anywhere -- as well as 'score', 'count', 'wrong', 'wrongcount' and several more.
divinity divinity

2016/4/15

#
hi danpost am going to post the whole codes that i have used even the variable so you will have a general idea of what i am talking about. here is whole codes that i have used.
package luanataylor_multiplicatiochoicegame;

import java.util.Scanner;
import java.util.Random;
 
public class Luanataylor_multiplicatiochoicegame 
{

    
    public static void main(String[] args) 
    {
        Scanner reader = new Scanner(System.in);
        
        Random randobj = new Random();
        
        
        
        int count = 0, playerage, rand1,question = 0, rand2, correct_ans = 0, intvalue=0, intvalue2=0, incorrect_ans = 0;
        char uSelect = 'a';
        int totalscore =0, wrongcount=0, score=0, wrong = 0, num1=0, num2=0;
        int total_correct = 0, total_incorrect = 0,largest =0,  smallest = 0;
        int numerator = 0, denominator = 0;
        int  question_no = 0, ans = 0;
        int i;
        
        System.out.println("Welcome to Solare School of Multiplication");
        System.out.println("The game is for kids between the ages of 8 and 13 year");
        System.out.println("The game has consist of 10 questions");
        System.out.println("The games does not accept any student below or above the age limit");
        System.out.println("The game has 3 rounds ");
        System.out.println("The first and second round has 4 questions and the last round has two questions");
        System.out.println("This game will end when the play enter the wrong age");
        
        System.out.println("                                                        ");
        
        System.out.println("Hi what is your name ");
        String playername = reader.next();
        System.out.println("oh, what a lovely name you have");
        System.out.println("Hi what is your age");
        playerage = reader.nextInt();
        
        if(playerage < 8 )
        {
            System.out.println(playername+" you are too young for this game");
            System.exit(0);
        }
        else if( playerage > 13)
        {
            System.out.println(playername+" you are to old for this game  ");
            System.exit(0);
        }
        else
        {
            System.out.println(playername+" kapow!!!! come let us have fun playing");
        }
        System.out.println("                                 ");
        
        System.out.println("***************round 1*********************************");
        
        System.out.println("                                          ");
        
        
        
        
        for(i = 1; i<=4; i++)
        {
            if(uSelect == 1)
            {
                //getting the random numbers
                intvalue = 1 + randobj.nextInt(25);
                intvalue = 2 + randobj.nextInt(8);
                correct_ans = intvalue + intvalue2;
                incorrect_ans = 75 + randobj.nextInt(75);
                
                System.out.println(playername+" you are starting on round 1 "+ " level "+ i + "question "+ i +" match the letter with the correct answer");
                System.out.println(playername+" please add "+intvalue + " + "+ intvalue);
                
                //implementing the letter for the correct answer
                System.out.println("A:"+correct_ans);
                System.out.println("B:"+incorrect_ans);
                uSelect = reader.next().charAt(0);
                
                if(uSelect == 'A' || uSelect == 'b')
                {
                    System.out.println(playername+" excellent and brilliant kiddo!!! answer is correct, keep up the good work");
                    score += score + 350;
                    System.out.println("round 1");
                    System.out.println("level "+ i);
                    System.out.println("question "+ i);
                    totalscore += score;
                    System.out.println("total score is: "+ totalscore);
                    count++;
                    wrong = wrongcount + i;
                }
                else if(uSelect == 'B' || uSelect == 'b')
                {
                    System.out.println(playername+" chittychitty bangbang!!!!  answer is wrong, try again");
                    score -= score - 175;
                    System.out.println("round: 1");
                    System.out.println("level: "+ i);
                    System.out.println("question: "+ i);
                    totalscore -=score;
                    System.out.println("total score "+ totalscore);
                    count++;
                    wrong = wrongcount + i;
                }
                else if(uSelect == 2)
                {
                    if(wrong > i)
                    {
                        System.out.println(playername+" you are still on round 1"+ "level "+ i +" question "+ i + " match the letter with the correct  answer");
                        System.out.println(playername+" please add "+ intvalue + " + "+ intvalue);
                        
                        //get the right letter to correct answer
                        System.out.println("A: "+correct_ans);
                        System.out.println("B: "+incorrect_ans);
                        uSelect = reader.next().charAt(0);
                        
                        if(uSelect == 'A' || uSelect == 'b')
                        {
                            System.out.println(playername+" brillian kiddoo!!! yesss correct is right ");
                            score += score + 350;
                            System.out.println("round 1");
                            System.out.println("level "+ i);
                            System.out.println("question: "+ i);
                            totalscore += score;
                            System.out.println("total score "+totalscore);
                            count++;
                        }
                        else if(uSelect == 'B' || uSelect == 'b')
                        {
                            System.out.println(playername+" awwww come one now, kiddooo that is so wrong");
                            score -= score - 175;
                            System.out.println("round 1");
                            System.out.println("level:"+ i);
                            System.out.println("question "+ i);
                            totalscore -=score;
                            System.out.println("total score is: "+totalscore);
                            count++;
                            wrong = wrongcount + i;
                        }
                        
                        
                    }
                }
                
            }
        }
                
        
        System.out.println("                                                      ");
        
        System.out.println("*********************welcome to round 2*******************************");
        
        System.out.println("                                                       ");
        
        int num = 0;
        for(i = 5; i<=8; i++)
        {
            //get random numbers
            largest  =  1 + randobj.nextInt(25);
            smallest =  2 + randobj.nextInt(8);
            correct_ans   = largest - smallest;
            incorrect_ans = 75 + randobj.nextInt(75);
            
            if(i == 1)
            {
                //getting the smallest and largest number so that the user can subtract from
                largest = num1;
                smallest = num2;
            }
            else
            {
                if(num1 > largest)
                {
                    largest = num1;
                }
                if(num2 > smallest)
                {
                    smallest = num2;
                }
            }
            //indicating the round and level is currently on and asking the used to choose the correct letter to the corresponding answers
            System.out.println(playername+" you are on round 2 "+ " level "+ i + " question "+ i +" match the letter with the correct answer");
            System.out.println(playername+" the largest and smallest number entered is: "+ "please subtract "+largest + " - "+ smallest);
            
            //inputting the correct ans
            System.out.println("A:"+ correct_ans);
            System.out.println("B:"+incorrect_ans);
            uSelect = reader.next().charAt(0);
            
            //checkin to see if the user would pick the correct answer 
            if(uSelect == 'A' || uSelect == 'a')
            {
                System.out.println(playername+" great you are doing good, correct is right");
                score += score + 350;
                System.out.println("round 2 ");
                System.out.println("level "+ i);
                System.out.println("question "+ i);
                totalscore +=score;
                System.out.println("total score "+totalscore);
                count++;
                wrong = wrongcount + i;
            }
            else if(uSelect == 'B' || uSelect == 'b')
            {
                //letting the user know they have entered the incorrect answer
                System.out.println(playername+" chiitychitty bangbang!!! that is incorrect, you need to know you tables, try again");
                score -= score -175;
                System.out.println("round 2 ");
                System.out.println("level "+ i);
                System.out.println("question " + i);
                totalscore -= score;
                System.out.println("total score is: "+ totalscore);
                wrongcount++;
                wrong = wrongcount + i;
                
                if(wrong > i)
                {
                    System.out.println(playername+" you are still on round 2 "+ "level "+ i + " question "+ i +" match the letter with the correct answer");
                    System.out.println(playername+"the largest and smallest number entered is: "+ largest + " - "+smallest);
                    
                    System.out.println("A: "+correct_ans);
                    System.out.println("B: "+incorrect_ans);
                    uSelect = reader.next().charAt(0);
                    
                    //checking to see if the user match the letter with the correct ans
                    if(uSelect == 'A'|| uSelect == 'a')
                    {
                       System.out.println(playername+" woow!!!! that is correct, keep up the good work");
                       score += score + 350;
                       System.out.println("round 2 ");
                       System.out.println("level "+ i);
                        System.out.println("question "+ i);
                       totalscore += score;
                       System.out.println("total score is "+totalscore);
                       count++;
                       wrong = wrongcount + i;
                    }
                    else if(uSelect == 'B'|| uSelect == 'b')
                    {
                        System.out.println(playername+" ooh no not again!!! that is not correct, please get it correct this time, try again");
                        score -= score - 175;
                        System.out.println("round 2 ");
                        System.out.println("level "+ i);
                        System.out.println("question "+ i);
                        totalscore -= score;
                        System.out.println("total score is "+totalscore);
                        wrongcount++;
                        wrong = wrongcount + i;
                        
                    }
                }
            }
            
        }
        System.out.println("                                               ");
        
        System.out.println("*******************welcome to round 3*****************************");
        
        System.out.println("                                                ");
        
        
        for(i=9; i<=10; i++)
        {
            //getting the random numbers
            numerator   = randobj.nextInt(25) + 1;
            denominator = 2 + randobj.nextInt(8);
            rand1 = 1 + randobj.nextInt(20);
            rand2 = 2 + randobj.nextInt(25);
            correct_ans = numerator = denominator * rand2;
            correct_ans = numerator / denominator;
            incorrect_ans = 25 + randobj.nextInt(75);
            
            System.out.println(playername+" you are on round 3 "+ " level "+ i +" question "+ i + " match the letter with the correct answer");
            System.out.println(playername+" please divide "+ numerator + " / " + denominator);
            
            //getting the corresponding answers to match the letter
            System.out.println("A: "+correct_ans);
            System.out.println("B: "+incorrect_ans);
            uSelect = reader.next().charAt(0);
            
            if(uSelect == 'A' || uSelect == 'a')
            {
                //checking to see if the user input the correct letter to the question asked
                System.out.println(playername+" brilliant kiddooo!!! you ar doing great, correct answer  ");
                score -= score - 175;
                System.out.println("round 3 ");
                System.out.println("level "+ i);
                System.out.println("question "+ i);
                totalscore -=score;
                System.out.println("total score "+totalscore);
                wrongcount++;
                wrong = wrongcount + i;
                
            }
            else if(uSelect == 'B' || uSelect == 'b')
            {
                System.out.println(playername+" tsk tsk nice bangbang!!! that is so wrong, try again kiddo!!!!! ");
                score += score + 375;
                System.out.println("round 3 ");
                System.out.println("level "+ i);
                System.out.println("question "+ i);
                totalscore += score;
                System.out.println("total score is: "+ totalscore);
                count++;
                
                
                if(wrong > i)
                {
                    System.out.println(playername+" you are still on round 3 "+ " level "+ i + " question "+ i + " match the letter to the correct answer");
                    System.out.println(playername+" please divide "+ numerator + " / "+ denominator);
                    
                    //get the matching letter to the correct answer
                    System.out.println("A:"+correct_ans);
                    System.out.println("B:"+incorrect_ans);
                    uSelect = reader.next().charAt(0);
                    
                    if(uSelect == 'A' || uSelect == 'a')
                    {
                        System.out.println(playername+" excellent job kiddoo!! you did good ");
                        score -= score - 175;
                        System.out.println("round 3 ");
                        System.out.println("level "+ i);
                        System.out.println("question "+ i);
                        totalscore -=score;
                        System.out.println("total score is: "+ totalscore);
                        wrongcount++;
                        wrong = wrongcount + i;
                    }
                    else if(uSelect == 'B' || uSelect == 'b')
                    {
                        System.out.println(playername+" ding dong you are wrong, nice try, come again");
                        score += score + 375;
                        System.out.println("round 3");
                        System.out.println("level "+ i);
                        System.out.println("question "+ i);
                        totalscore += score;
                        System.out.println("total score is: "+totalscore);
                        count++;
                        wrong = wrongcount + i;
                    }
                }
                
            }
            
        }
danpost danpost

2016/4/15

#
Well, you set the initial value of 'uSelect' to 'a'. So, its value is not one and it is not two -- actually, setting it to 'a' would make its value ninety-seven (if I am not mistaken). So, since it is not one or two, the first major 'if-else' segment is passed up and your second question begins. This brings another issue, The second question has a 'for' loop that iterates, using i', from five to eight; however, within the block, you ask if the value of 'i' is 1, which will never be true there. You may have a misplaced closing squiggly bracket that might belong next to line 106. I think that the 'else' phrase on 107 is supposed to link with the 'if' on line 67. Also, it seems odd that you ask if 'uSelect' is 'b' on both lines 83 and 95 (I think line 83 should ask about 'a', not 'b').
divinity divinity

2016/4/15

#
so can i set the uSelect to either 1 or a what i mean is set the one to a or set the a to 1 just asking
danpost danpost

2016/4/15

#
divinity wrote...
so can i set the uSelect to either 1 or a what i mean is set the one to a or set the a to 1 just asking
I guess you could use a Map object to do that, but I would not recommend it. Each character already has a unique value associated with it. -- its character code (now termed Unicode). "A' is 65. 'a' is 97. '1' is 49 (I think).
divinity divinity

2016/4/15

#
i tried it but started to work but the answer i get was. please add: 4 + 4 a: 4 b:102 that is the result ah got when i did that. so back to the drawing board. out of clues as to try next might have to go back to my original codes. if only ah could get this to work the way ah want it to work.
danpost danpost

2016/4/15

#
You should probably get the random numbers for the problem before the for loop where the user attempts to answer it.
You need to login to post a reply.