OrangeSoul Posted July 8, 2004 Share Posted July 8, 2004 I need help with the following coding: 1) Generating Random numbers between 60 and 100 for 2 objects, object1 and object2 2) Comparing the Random numbers generated in (1) for object1 and object2 and finding which one is greater 3) Coding such that if object1 has a bigger Random number than object2 then object1 gains 1 point 4) The coding ends when either Object1 or Object2 reach 4 points first Thanks Link to comment Share on other sites More sharing options...
0 lime Posted July 8, 2004 Share Posted July 8, 2004 so for 1 you need to generate random numbers until you get one between 60 and 100, once that happens store the first one in object1, then do the same thing for object 2 2. that's extremely easy, if (object1 > object2).....then object1point++ and the other way.... 3. answered ^ 4. so you need to do those things above in a while loop.... while ( (object1point < 4) && (object2point < 4) ) that should be all you need....it's not to hard....for the random number just look at the java api and rand() Link to comment Share on other sites More sharing options...
0 Chadwick Posted July 9, 2004 Share Posted July 9, 2004 well, i think this is an exercise for classes, he did say object ;) your object class should have: -random number generator function (generates and saves to private variable) -private score variable -accessor functions than you can compare easily by calling class functions Link to comment Share on other sites More sharing options...
Question
OrangeSoul
I need help with the following coding:
1) Generating Random numbers between 60 and 100 for 2 objects, object1 and object2
2) Comparing the Random numbers generated in (1) for object1 and object2 and finding which one is greater
3) Coding such that if object1 has a bigger Random number than object2 then object1 gains 1 point
4) The coding ends when either Object1 or Object2 reach 4 points first
Thanks
Link to comment
Share on other sites
2 answers to this question
Recommended Posts