img
FIGURE 32-4
The Annuity applet
where rateOfRet specifies the rate of return, regWD contains the desired regular withdrawal,
wdPerYear specifies the number of withdrawals per year, and numYears specifies the length
of the annuity in years.
The Annuity applet shown here computes the initial investment required to produce
the desired annuity. The applet produced by this program is shown in Figure 32-4.
/* Compute the initial investment necessary for
a desired annuity. In other words, it finds
the initial amount needed to allow the regular
withdrawals of a desired amount over a period
of time.  */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
/*
<applet code="Annuity" width=340 height=260>
</applet>
*/
public class Annuity extends JApplet
implements ActionListener {
JTextField regWDText, initialText, periodText,
rateText, numWDText;
JButton doIt;
double regWDAmount;
//
amount of each withdrawal
double rateOfRet;
//
rate of return
double numYears;
//
length of time in years
int numPerYear;
//
number of withdrawals per year
NumberFormat nf;
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable () {
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home