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

2016/4/24

why is my game skipping round two

1
2
divinity divinity

2016/4/24

#
hi i am building my final project tell me why it is skipping the whole round two and why is it giving me zero to divide it is not supposed to random any zero at all here is my code
 
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 if(playerage >= 8 && playerage <= 13)//round 1
        {
            System.out.println("\n***************round 1**********************\n");
            System.out.println("\n this round is the addition round");
        
            while( i<4 && wrongcount < 4)
            {
                //get the random numbers
                i++;
                intvalue  = 1 + randobj.nextInt(25);
                intvalue2 = 1 + randobj.nextInt(9);
                correct_ans = intvalue + intvalue2;
                incorrect_ans = 1 + randobj.nextInt(35);
                
                while(correct_ans == incorrect_ans)
                {
                   incorrect_ans = 1 + randobj.nextInt(35);
                }

                //indicating to the user where she would be starting from and what level
                System.out.println(playername+" you are on round 1 "+ " level "+ i + " match the letter with the correct answer");
                System.out.println(playername+" please add "+ intvalue + " + "+intvalue2);

                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+" well done kiddoo!!  excellent keep up the good work");
                    totalscore += 350;
                    System.out.println("round 1");
                    System.out.println("level "+ i);
                    totalscore += score;
                    System.out.println("total score "+ totalscore);
                }
                else 
                {
                    while(uSelect != 'A'&& uSelect != 'a' && wrongcount < 4)
                    { 
                        System.out.println(playername+" okay let me catch my breath here, answer is incorrect, try again");
                        score -= 175;
                        System.out.println("round 1");
                        System.out.println("level "+ i);
                        totalscore -= score;
                        System.out.println("total score: "+ totalscore);
                        wrongcount++;

                        if(wrongcount < 4)
                        {
                            System.out.println(playername+" you are still on round 1 "+" level "+ i +" match the letter with the correct ansswer");
                            System.out.println(playername+" please add "+ intvalue + " + "+ intvalue2);

                            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+" yah, good job, keep it up, answer is correct");
                            score +=  350;
                            System.out.println("round 1");
                            System.out.println("level "+ i);
                            totalscore =score;
                            System.out.println("total score: "+ totalscore);
                             
                        }
                        else 
                        {
                            System.out.println(playername+" no man, come on, you can do better than that, it wrong");
                            score -= 175;
                            System.out.println("round 1");
                            System.out.println("level "+ i);
                            totalscore =score;
                            System.out.println("total score: "+ totalscore);
                            
                            wrongcount++;
                        }*/
                    }
                }
            }
        
            System.out.println("\n*********************welcome to round 2*******************************\n");
            System.out.println("\n this is the substraction round");

            int num = 0;
            
            while(i>=5 && i<=8 && wrongcount <4)
            {
                i++;
                //get random numbers
                largest  = 1 + randobj.nextInt(25);
                smallest = 1 + randobj.nextInt(9);
                correct_ans = largest - smallest;
                incorrect_ans = 1 + randobj.nextInt(35);
                
                while(correct_ans == incorrect_ans)
                {
                    incorrect_ans = 1 + randobj.nextInt(35);
                }
                if(i == 1)
                {
                    //getting the largest and smallest number 
                    largest  = num1;
                    smallest = num2;
                }
                else
                {
                    if(num1 > largest)
                    {
                        largest = num1;
                    }
                    if(num2 > smallest)
                    {
                        smallest = num2;
                    }
                }
                //indicate the round and level would be starting from
                System.out.println(playername+" round 2 "+" level "+ i +" match the letter with the correct answer");
                System.out.println(playername+" please subtract "+ largest + " - "+smallest);
                
                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+"");
                    totalscore +=350;
                    System.out.println("round 2");
                    System.out.println("level "+i);
                    totalscore +=score;
                    System.out.println("total score it"+totalscore);
                }
                else 
                {
                    while(uSelect != 'A' && uSelect != 'a' & wrongcount < 4)
                    {
                        System.out.println(playername+" awww come on now wrong answer, let's do this again ");
                        totalscore -=175;
                        System.out.println("round 2");
                        System.out.println("level "+ i);
                        totalscore -=score;
                        System.out.println("total score:"+totalscore);
                        
                        if(wrongcount <4)
                        {
                            System.out.println(playername+" round 2 "+ "level "+ i+" match the letter with the correct answer");
                            System.out.println(playername+" please subtract "+ largest + " - "+ smallest);
                            
                            System.out.println("A:"+correct_ans);
                            System.out.println("B:"+incorrect_ans);
                            uSelect = reader.next().charAt(0);
                            
                        }
                    }
                }
            }
           
            
            System.out.println("\n*******************welcome to round 3*****************************");
            
            System.out.println("\n this round is the division round");

            while(i>=9 && i<=10 && wrongcount < 4)
            {
                i++;
                //get random numbers
                numerator   = 1 + randobj.nextInt(25);
                denominator = 2 + randobj.nextInt(9);
                rand  = 1 + randobj.nextInt(25);
                rand2 = 2 + randobj.nextInt(9);
                correct_ans = numerator = denominator * rand2;
                correct_ans = numerator / denominator;
                incorrect_ans = 1 + randobj.nextInt(35);
                
                while(correct_ans == incorrect_ans)
                {
                    incorrect_ans = 1 + randobj.nextInt(35);
                }
                System.out.println(playername+" you are on round 3 "+" level "+ i + " match the letter with the correct answer");
                System.out.println(playername+" please divide "+ numerator + " / "+ denominator);
                
                System.out.println("A:"+incorrect_ans);
                System.out.println("B:"+correct_ans);
                uSelect = reader.next().charAt(0);
                
                if(uSelect == 'A' || uSelect == 'a')
                {
                    System.out.println(playername+" hey that's great, correct is right, keep up the good worl");
                    totalscore +=350;
                    System.out.println("round 3");
                    System.out.println("level "+i);
                    totalscore +=score;
                    System.out.println("total score:"+totalscore);
                }
                else
                {
                    while(uSelect !='A' && uSelect !='a' && wrongcount < 4)
                    {
                        System.out.println(playername+" tsk, tsk, nice bangbang!!! that is wrong, please try again, kiddooo!!!");
                        totalscore -=175;
                        System.out.println("round 3");
                        System.out.println("level "+ i);
                        totalscore -=score;
                        System.out.println("total score: "+totalscore);
                        
                    }
                }
                
            }
            while(wrongcount < 4)
            {
                System.out.println(playername+" you are on round 3 "+ " level "+ i + " match the letter with the correct answer");
                System.out.println(playername+" please divide "+ numerator + " / "+ denominator);
                
                System.out.println("A:"+incorrect_ans);
                System.out.println("B:"+correct_ans);
                uSelect = reader.next().charAt(0);
                
            }
        }    
        else
        {
            System.out.println(playername+"that is not a valid age");
        }
        System.out.println("the winner is "+playername);
        System.out.println("the total score of the game is "+totalscore);
        System.out.println("the level that the player was on is"+ "level "+i);
        System.out.println("the number of chance left is"+wrongcount);
    }
      
}
danpost danpost

2016/4/24

#
The 'while' loop starting on line 17 and ending on line 93 will execute until either 'i' or 'wrongCount' becomes '4'; so, the condition on line 100 will never be met. The main thing is that 'i' will never be 5 or greater.
divinity divinity

2016/4/24

#
so what am i supposed to do then to make it work and how do i get the third round to give me the random number instead of zero.
divinity divinity

2016/4/24

#
the while loop on line 17 is the start of the first round so when it reach to line 93 it is supposed to go on from 5 -8 and then to round three where is on two question. there are logical error how do i fix it
danpost danpost

2016/4/24

#
divinity wrote...
the while loop on line 17 is the start of the first round so when it reach to line 93 it is supposed to go on from 5 -8
You could explicitly set the value of 'i' to '5' after the first 'while' loop -- or you could change the condition on line 100 to:
while (i>=4 && i<=7 && wrongcount<4)
and then to round three where is on two question. there are logical error how do i fix it
What error are you getting? Copy/paste terminal output here. What line is the error occurring on?
divinity divinity

2016/4/24

#
no what i mean round 1 supposed to run from 1-4, round 2 is from 5-8, round 3 is from 9-10, and the error that I am getting is logical errors, not syntax error or runtime error but logic errors. somewhere in round 2 and round 3 is logic error is.
danpost danpost

2016/4/24

#
divinity wrote...
no what i mean round 1 supposed to run from 1-4, round 2 is from 5-8, round 3 is from 9-10,
danpost wrote...
You could explicitly set the value of 'i' to '5' after the first 'while' loop
You should probably to what I said here (as well as after round 2 -- set the value of 'i' to '9').
the error that I am getting is logical errors, not syntax error or runtime error but logic errors. somewhere in round 2 and round 3 is logic error is.
I will look into this to see if I can figure out what is going on there.
danpost danpost

2016/4/24

#
Line 97 shows 'B' being assigned to the correct answer; yet, you are coding the response to the user's answer as if 'A' was the correct one.
divinity divinity

2016/4/24

#
hi danpost another problem am having and what i forget to mention is, in round 3, it supposed to say round 3 level 9 instead it saying round 3 level 4 and this is the random it is generation zero for the user to divide. it must not generate no random zero, here is what am speaking about why is it generating zero for the user to divide. what causing it to generate zero ken you are on round 3 level 4 match the letter with the correct answer ken please divide 0 / 0 A:13 B:17
divinity divinity

2016/4/24

#
hi in round 2 how can i set i to the value of 9 when in round 2 is from 5-8 and in round 3 is 9-10
danpost danpost

2016/4/24

#
You need to adjust your initial 'while' conditions for values one less than the first and last levels for the rounds as you start the blocks by immediately incrementing the value of 'i'. Then you do not have to explicitly set the value of 'i' between rounds. As far as '0/0': you should get a run-time error on 186 before it prints out that line with '0/0' in it. Although I do not think the following will change anything, here goes: Line 181 can be removed. You are setting its value of the 'numerator' field (regardless of any value set on line 181) to the product of two different fields on line 185. Line 183 can be removed because 'rand' is not used anywhere. Line 186 can be removed and line 184 can be changed to the following to compensate:
rand2 = correct_ans = 2 + randobj.nextInt(9);
What you end up with then (to replace lines 177 to 187) is:
while(i>=8 && i<=9 && wrongcount < 4)
{
    i++;
    //get random numbers
    denominator = 2 + randobj.nextInt(9);
    rand2 = correct_ans = 2 + randobj.nextInt(9);
    numerator = denominator * rand2;
    incorrect_ans = 1 + randobj.nextInt(35);
The last line here seems a bit peculiar in that about half of the time the incorrect answer will be larger than the numerator making it easy to disqualify it as the correct answer. Using a number line '25' would be better (about half the time, then); and maybe using '10' would be best (infrequently).
divinity divinity

2016/4/24

#
hi danpost sorry to say again, it not working, i tried it but am not getting output, non
danpost danpost

2016/4/24

#
divinity wrote...
hi danpost sorry to say again, it not working, i tried it but am not getting output, non
I just noticed some duplicate code here. Remove lines 224 through 233. You may want to perform a 'System.exit(0)' after line 237 as well. I am not saying this will fix anything; but, it cannot hurt to get rid of junk code and exit at an appropriate time. Maybe your loops for the different rounds should be 'for' loops instead of 'while' loops as you already know how many questions are in each round. If you need to exit the loop early, you can use a 'break' statement. It may be possible to make use of the 'continue' statement, as well. I will try to come up with a system that might work and post back my findings.
danpost danpost

2016/4/24

#
I found that a 'for' loop is best to interate through ALL the questions (since all three rounds begin at a level number of one plus a multiple of four). Then a boolean value can be used to determine if the question for a level has been created yet or not. On a correct answer (after finalizing the level), you can use a 'continue' statement to proceed to the next level. On an incorrect answer, you can decrement the level iterator value to try the same question over again. On the fourth incorrect answer, you can use a 'break' statement to exit the loop.
divinity divinity

2016/4/24

#
as soon as i fixed everything else i will delete the junk codes and dem
There are more replies on the next page.
1
2