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

2015/12/21

what java codes do i used to get the numerator to be divisible by the denominator always

divinity divinity

2015/12/21

#
I am also doing another programming assignment. this one is a multiple choice game. where it have three rounds. round 1 is the addition round round 2 is the subtraction round round 3 is the division my problem is the division round which is round 3. I have already figure out round 1 and 2, there is no problem there. the problem is round three i have manage to got it to divide yes but not the way how it is supposed to work. you see, the numerator must always be divisible by the denominator at all time. what I am getting is that numerator is being divided by numbers that cannot into it. the numbers have to be randomly generated. what i mean is the: 11/6 or 25/7 which is not supposed to do. any help with be greatly appreciated on how i can get the codes to work like this 20/4 or 24/3 and so on. here is the codes that i have so far.
  i=1;
                        while(i < 2)//this while loop is used to know how many time it will be iterating
                        {
                            if(i<2)
                            {
                                numerator   = 1 + randobj.nextInt(25);
                                denominator = 2 + randobj.nextInt(8);
                                
                                correctans = numerator / denominator;
                                incorrectans = 25 + randobj.nextInt(50);
                                
                                if(numerator %2!=denominator)
                                {

                                    System.out.println(playername+" round 3 "+ " level "+ i+" question "+ i + " you are required to math the letter to the correct answer");
                                     System.out.println(playername+" please divide "+ numerator + " / "+ denominator);
                                   
                                
                                    System.out.println("A:"+correctans);
                                    System.out.println("B:"+incorrectans);
                                    choice = userinput.next().charAt(0);
                                
                                
                                
                                      if(choice == 'A' || choice == 'a')
                                {
                                        System.out.println(playername+" awesome, you are correct, well done, keep up the good work");
                                        score += score + 250;
                                        System.out.println("round 3");
                                        System.out.println("level "+ i);
                                        score += score;
                                        System.out.println("the total score is "+ totalscore);
                                        correctans++;// to keep a count of all the correct answer
                                }
                                else if(choice == 'B' || choice == 'b')
                                {
                                    System.out.println(playername+" ahhh bummer!!! that is not the correct answer, so sorry, give it another try");
                                    score -= score - 125;
                                    System.out.println("round 3");
                                    System.out.println("level "+i);
                                    totalscore -= score;
                                    System.out.println("the total score is "+ totalscore);
                                    i++;
                                }
                           
                                }
                            }
danpost danpost

2015/12/21

#
Just generate the divisor and the quotient; then multiply to produce the dividend.
divinity divinity

2015/12/21

#
i dont understand how can i get it to do just that any example would help
Super_Hippo Super_Hippo

2015/12/21

#
A / B = C Right now, you get random numbers for A and B. Instead, you could get random numbers for B and C. Then you calculate A with it: A = B * C
divinity divinity

2015/12/21

#
thnk you oooooh so much now one issue it looks like ah have to generate another random number but how do i do that
divinity divinity

2015/12/21

#
hi super_hippo I want to thank you very much for helping me out. i did what you suggested and I got it to work just the way ah want it to work. ah want to wish you ah merry christimas and a happy new year to you and yours.
You need to login to post a reply.