Java Reference
In-Depth Information
Q UIZ
Answer the quiz for this chapter online at www.cs.armstrong.edu/liang/intro10e/quiz.html .
P ROGRAMMING E XERCISES
Sections 15.2-15.7
*15.1
( Pick four cards ) Write a program that lets the user click the Refresh button to
display four cards from a deck of 52 cards, as shown in Figure 15.24a. (See the
hint in Programming Exercise 14.3 on how to obtain four random cards.)
(a)
(b)
(c)
F IGURE 15.24
(a) Exercise 15.1 displays four cards randomly. (b) Exercise 15.2 rotates the rectangle. (c) Exercise 15.3
uses the buttons to move the ball.
15.2
( Rotate a rectangle ) Write a program that rotates a rectangle 15 degrees right
when the Rotate button is clicked, as shown in Figure 15.24b.
*15.3
( Move the ball ) Write a program that moves the ball in a pane. You should
define a pane class for displaying the ball and provide the methods for moving
the ball left, right, up, and down, as shown in Figure 15.24c. Check the bound-
ary to prevent the ball from moving out of sight completely.
*15.4
( Create a simple calculator ) Write a program to perform addition, subtraction,
multiplication, and division, as shown in Figure 15.25a.
VideoNote
Simple calculator
(a)
(b)
F IGURE 15.25
(a) Exercise 15.4 performs addition, subtraction, multiplication, and division
on double numbers. (b) The user enters the investment amount, years, and interest rate to
compute future value.
*15.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
 
Search WWH ::




Custom Search