1. Member
Join Date
Feb 2009
Posts
27
Rep Power
0

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:

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:

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:
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....

/**
*
*/
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;

}

}

2. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
create a Frog
what you mean saying that ?

3. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
public void hop (int n){
for (int i=0; i < n; i++)
this.hop();
}
does it provides a problem?

4. Member
Join Date
Feb 2009
Posts
27
Rep Power
0
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.

5. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
working, change the number of frogs to 10000 instead of 10. Each
demands for any visualization ?
Is that a game or what?

6. Senior Member
Join Date
Sep 2008
Posts
564
Rep Power
5
i'm confused, but aren't you just implementing the pseudo-code given in 'part 3'?

7. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
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?

8. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
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?
Last edited by Webuser; 02-13-2009 at 05:04 AM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•