Java Reference
In-Depth Information
**28.11
( Revise Listing 28.14, NineTail.java ) The program in Listing 28.14 lets the user
enter an input for the nine tails problem from the console and displays the result
on the console. Write a program that lets the user set an initial state of the nine
coins (see Figure 28.22a) and click the Solve button to display the solution, as
shown in Figure 28.22b. Initially, the user can click the mouse button to flip a
coin. Set a red color on the flipped cells.
(a)
(b)
F IGURE 28.22
The program solves the nine tails problem.
**28.12
( Variation of the nine tails problem ) In the nine tails problem, when you flip a
coin, the horizontal and vertical neighboring cells are also flipped. Rewrite the
program, assuming that all neighboring cells including the diagonal neighbors
are also flipped.
**28.13
( 4
4 16 tails problem ) Listing 28.14, NineTail.java, presents a solution for
the nine tails problem. Revise this program for the 4
*
4 16 tails problem.
Note that it is possible that a solution may not exist for a starting pattern. If so,
report that no solution exists.
*
**28.14
( 4
*
4 16 tails analysis ) The nine tails problem in the text uses a 3
*
3 matrix.
Assume that you have 16 coins placed in a 4
4 matrix. Write a program to
find out the number of the starting patterns that don't have a solution.
*
*28.15
*
( 4
4 16 tails GUI ) Rewrite Programming Exercise 28.14 to enable the user to
set an initial pattern of the 4
*
4 16 tails problem (see Figure 28.23a). The user
can click the Solve button to display the solution, as shown in Figure 28.23b.
Initially, the user can click the mouse button to flip a coin. If a solution does not
exist, display a message to report it.
(a)
(b)
F IGURE 28.23
The problem solves the 16 tails problem.
 
Search WWH ::




Custom Search