• 0

Java Coding Help


Question

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

  • 0

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

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.