-
Advice needed
Hi guys
I'm still not very confident in reading tasks, can you please help where I suppose to use if statement, any loops, how many if statements? please
Write a public instance method called advanceAllRacingFrogs() which takes
no argument and returns no value.
Provided that the race is not over the method should advance each racingfrog
taking part in the race a random number of stones (between 1 and 3 inclusive) to
the right, one stone at a time. For example if all the racingfrogs are selected to run
in the race, racingFrog1 should advance between 1 and 3 steps first, followed
by racingFrog2 and then racingFrog3. However, if advancing a racingfrog
causes it to win the race, the remaining racingfrog(s) selected to race should not
move. If the race is over the method should do nothing. To keep the code simple
the selected racingfrogs should move in ascending numerical order (even though
this gives an advantage to the lower numbered racingfrogs).
[To make the race fair, the order in which the racingfrogs move should be chosen
at random since the one that moves first clearly has an advantage. However, you
should not attempt to code this as it would involve a more sophisticated use of
random numbers than is relevant to this question’s assessment aims.]
so my attempt is
public void advanceAllRacingFrogs()
{
while(this.raceOver !=true) //provided is not over
{
if(this.getRacingFrog1().getSelected())
{
this.advanceRacingFrog(racingFrog1)
}
..... and so on until the loop will go trough all selected frogs
}
but what with other statements, where shall i put them, in the same loop other, please all suggestions will be highly appreaciated
lucas
-
Re: Advice needed
"
Provided that the race is not over the method should advance each racingfrog
taking part in the race a random number of stones (between 1 and 3 inclusive) to
the right, one stone at a time.
"
That does not imply a loop inside this method.
-
Re: Advice needed
oh i see, and how many if statements do i need?
-
Re: Advice needed
No idea.
Read through the description (that sentence in particular) and see how many ifs you can spot. That'll be the minimum, as some might fall out of implementing other bits.
Actually, I correct myself a bit from the earlier post...that requirement does not imply a loop where you put it, but:
"
...one stone at a time.
"
does imply a loop.
-
Re: Advice needed