Java Reference
In-Depth Information
***15.33
( Game: bean-machine animation ) Write a program that animates the bean
machine introduced in Programming Exercise 7.21. The animation terminates
after ten balls are dropped, as shown in Figure 15.36b and c.
***15.34
( Simulation: self-avoiding random walk ) A self-avoiding walk in a lattice is a
path from one point to another that does not visit the same point twice. Self-
avoiding walks have applications in physics, chemistry, and mathematics. They
can be used to model chain-like entities such as solvents and polymers. Write
a program that displays a random path that starts from the center and ends at a
point on the boundary, as shown in Figure 15.37a or ends at a dead-end point
(i.e., surrounded by four points that have already been visited), as shown in
Figure 15.37b. Assume the size of the lattice is 16 by 16 .
(a)
(b)
(c)
(d)
F IGURE 15.37
(a) A path ends at a boundary point. (b) A path ends at dead-end point. (c and d) Animation shows the
progress of a path step by step.
***15.35
( Animation: self-avoiding random walk ) Revise the preceding exercise to dis-
play the walk step by step in an animation, as shown in Figure 15.37c and  d.
**15.36
( Simulation: self-avoiding random walk ) Write a simulation program to show
that the chance of getting dead-end paths increases as the grid size increases.
Your program simulates lattices with size from 10 to 80. For each lattice size,
simulate a self-avoiding random walk 10,000 times and display the probability
of the dead-end paths, as shown in the following sample output:
For a lattice of size 10, the probability of dead-end paths is 10.6%
For a lattice of size 11, the probability of dead-end paths is 14.0%
...
For a lattice of size 80, the probability of dead-end paths is 99.5%
 
 
Search WWH ::




Custom Search