Java Reference
In-Depth Information
Figure 10.2
The initial state of the
foxes-and-rabbits
simulation
Exercise 10.2 Does the number of foxes change on every step? What natural processes do
you think we are modeling that cause the number of foxes to increase or decrease?
Exercise 10.3 Call the simulate method with a parameter to run the simulation continu-
ously for a significant number of steps, such as 50 or 100. Do the numbers of foxes and rab-
bits increase or decrease at similar rates?
Exercise 10.4 What changes do you notice if you run the simulation for a much longer time,
say for 4,000 steps? You can use the runLongSimulation method to do this.
Exercise 10.5 Use the reset method to create a new starting state for the simulation, and
then run it again. Is an identical simulation run this time? If not, do you see broadly similar pat-
terns emerging anyway?
Exercise 10.6 If you run a simulation for long enough, do all of the foxes or all of the rabbits
ever die off completely? If so, can you pinpoint any reasons why that might be occurring?
Exercise 10.7 Make a note of the numbers of foxes and rabbits at each of the first few
steps and at the end of a long run. It will be useful to have a record of these when we come to
make changes later on and perform regression testing.
Exercise 10.8 After having run the simulation for a while, reset it and also call the static
reset method of the Randomizer class. Now run the first few steps again, and you should
see the original simulation repeated. Take a look at the code of the Randomizer class to see
if you can work out why this might be. You might need to look at the API for the java.util.
Random class to help you with this.
 
Search WWH ::




Custom Search