• 02-12-2009, 07:00 AM
chango77745
I am working this program, but I cannot seem to think of how to do this question...will someone PLEASE help me.

The question states:

Quote:

Add a getNumberHome method to Frog that returns the number of times this Frog has landed on position 0. Add test statements to FrogTester to test this method.
Most importantly:

Quote:

Add code to FrogTester to perform the experiments described in Part III, but calling the new hop method of Frog rather than hopFrog of FrogTester for the inner loop. After you get this working, change the number of frogs to 10000 instead of 10. Each frog still makes 100 hops.
Part 3 states this:
Quote:

Suppose that we wanted to perform 10 experiments in which we create a Frog and have it hop 100 times. We compute the average of the following quanties oval all experiments: the final position, the final distance from the origin, the minimum position, and the maximum position. A straightforward implementation suggests a nested loop:

initialize overall statistics
for experiments 1 to 10
create a Frog
for hops 1 to 100
make Frog hop
output the Frog
update overall statistics
output overall statistics

The inner loop in this algorithm should be replaced by a method call. We can either make a static method in FrogTester to do the hopping:
public static void hopFrog(Frog thisFrog, int n)
or we can provide an additional version of the hop method in the Frog class:
public void hop (int n)
This is what I have so far....

Quote:

/**
*
*/
package frogs;
import java.util.*;
/**
* @author epena
*
*/
public class Frog {

private int hopsTaken;
private int position;
private int minimumPosition;
private int maximumPosition;

private static Random rand = new Random();

//Constructor
public Frog (){
hopsTaken = 0;
position = 0;
minimumPosition = 0;
maximumPosition = 0;
}
public int getPosition(){
return position;
}
public int getHopsTaken(){
return hopsTaken;
}
public int getMinimumPosition(){
return minimumPosition;
}
public int getMaximumPosition(){
return maximumPosition;
}
public void hop (int n){
for (int i=0; i < n; i++)
this.hop();

}
public void hop(){
int nextVal;
nextVal = rand.nextInt(2);
if (nextVal == 0)
position++;
else
position--;
hopsTaken++;
if (position < minimumPosition)
minimumPosition = position;
if (position < maximumPosition)
maximumPosition = position;
}

public String toString(){
String output = "Frog at " + position + " after " + hopsTaken + " hops ";
output += "with minimum position " + minimumPosition + " and maximum position " + maximumPosition;
return output;

}

}
• 02-12-2009, 07:20 AM
Webuser
Quote:

create a Frog
what you mean saying that ?
• 02-12-2009, 07:22 AM
Webuser
Quote:

public void hop (int n){
for (int i=0; i < n; i++)
this.hop();
}
does it provides a problem?
• 02-12-2009, 05:29 PM
chango77745
No that part is good, it's the what it's asking that I don't understand.

Add code to FrogTester to perform the experiments described in Part III, but calling the new hop method of Frog rather than hopFrog of FrogTester for the inner loop. After you get this working, change the number of frogs to 10000 instead of 10. Each frog still makes 100 hops.
• 02-13-2009, 01:35 AM
Webuser
Quote:

working, change the number of frogs to 10000 instead of 10. Each
demands for any visualization ?
Is that a game or what?
• 02-13-2009, 02:25 AM
emceenugget
i'm confused, but aren't you just implementing the pseudo-code given in 'part 3'?
• 02-13-2009, 05:57 AM
Webuser
Quote:

Suppose that we wanted to perform 10 experiments in which we create a Frog and have it hop 100 times.
what means create a frog. 2D graphics or it a fictional frog?
• 02-13-2009, 06:01 AM
Webuser
how you know where an event come from? If not to think in details it is clear that you need to create a tamplate for something . this something is not clear, right?