Java Reference
In-Depth Information
<param name
=
FONTNAME
value
=
"Monospaced"
/>
<param name
=
FONTSIZE
value
=
20
/>
</applet>
**18.5
(
Game: a clock learning tool
) Develop a clock applet to show a first-grade stu-
dent how to read a clock. Modify Programming Exercise 13.19 to display a
detailed clock with an hour hand and a minute hand in an applet, as shown in
Figure 18.17a. The hour and minute values are randomly generated. The hour
is between
0
and
11
, and the minute is
0
,
15
,
30
, or
45
. Upon a mouse click, a
new random time is displayed on the clock.
(a)
(b)
(c)
F
IGURE
18.17
(a) Upon a mouse click on the clock, the clock time is randomly displayed.
(b) Clicking the
New Game
button starts a new game. (c) The tax calculator computes the
tax for the specified taxable income and tax status.
**18.6
(
Game: tic-tac-toe
) Rewrite the program in Listing 18.10 TicTacToe.java with
the following modifications:
■
Define
Cell
as a separate class rather than an inner class.
Add a button named
New Game
, as shown in Figure 18.17b. Clicking the
New Game
button starts a new game.
■
**18.7
(
Financial application: tax calculator
) Create an applet to compute tax, as
shown in Figure 18.17c. The applet lets the user select the tax status and enter
the taxable income to compute the tax based on the 2001 federal tax rates, as
shown in Programming Exercise 10.8.
***18.8
(
Create a calculator
) Use various panels of
FlowLayout
,
GridLayout
, and
BorderLayout
to lay out the following calculator and to implement addition
(
+
), subtraction (
-
), division (
/
), square root (
sqrt
), and modulus (
%
) func-
tions (see Figure 18.18a).
(a)
(b)
F
IGURE
18.18
(a) Exercise 18.8 is a Java implementation of a popular calculator.
(b) Exercise 18.9 converts between decimal, hex, and binary numbers.