Results 1 to 8 of 8
- 02-12-2009, 06:00 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 27
- Rep Power
- 0
Please help with this problem....
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:
Most importantly: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.
Part 3 states this: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.
This is what I have so far....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)
/**
*
*/
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, 06:20 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
what you mean saying that ?create a Frog
- 02-12-2009, 06:22 AM #3
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
does it provides a problem?public void hop (int n){
for (int i=0; i < n; i++)
this.hop();
}
- 02-12-2009, 04:29 PM #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.
- 02-13-2009, 12:35 AM #5
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
demands for any visualization ?working, change the number of frogs to 10000 instead of 10. Each
Is that a game or what?
- 02-13-2009, 01:25 AM #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'?
- 02-13-2009, 04:57 AM #7
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
what means create a frog. 2D graphics or it a fictional frog?Suppose that we wanted to perform 10 experiments in which we create a Frog and have it hop 100 times.
- 02-13-2009, 05:01 AM #8
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks