Java Reference
In-Depth Information
*16.5
( Create an investment-value calculator ) Write a program that calculates the
future value of an investment at a given interest rate for a specified number of
years. The formula for the calculation is:
futureValue = investmentAmount * (1 + monthlyInterestRate) years*12
Use text fields for the investment amount, number of years, and annual interest
rate. Display the future amount in a text field when the user clicks the Calculate
button, as shown in Figure 16.22a.
(a)
(b)
(c)
F IGURE 16.22 (a) The user enters the investment amount, years, and interest rate to compute
future value. (b) Exercise 16.8 displays the mouse position. (c) Exercise 16.9 uses the arrow
keys to draw the lines.
Sections 16.8-16.9
**16.6
( Alternate two messages ) Write a program to rotate with a mouse click the two
messages Java is fun and Java is powerful displayed on a panel.
*16.7
( Set background color using a mouse ) Write a program that displays the back-
ground color of a panel as black when the mouse button is pressed and as white
when the mouse button is released.
*16.8
( Display the mouse position ) Write two programs, such that one displays the
mouse position when the mouse button is clicked (see Figure 16.22b) and the
other displays the mouse position when the mouse button is pressed and ceases
to display it when the mouse button is released.
Section 16.10
*16.9
( Draw lines using the arrow keys ) Write a program that draws line segments
using the arrow keys. The line starts from the center of the frame and draws
toward east, north, west, or south when the right-arrow key, up-arrow key, left-
arrow key, or down-arrow key is pressed, as shown in Figure 16.22c.
**16.10
( Enter and display a string ) Write a program that receives a string from the key-
board and displays it on a panel. The Enter key signals the end of a string.
Whenever a new string is entered, it is displayed on the panel.
*16.11
( Display a character ) Write a program to get a character input from the key-
board and display the character where the mouse points.
Section 16.11
**16.12
( Display a running fan ) Listing 13.4, DrawArcs.java, displays a motionless fan.
Write a program that displays a running fan.
**16.13
( Slide show ) Twenty-five slides are stored as image files ( slide0.jpg , slide1.jpg ,
. . ., slide24.jpg ) in the image directory downloadable along with the source
code in the topic. The size of each image is
800
*
600.
Write a Java application
 
Search WWH ::




Custom Search