img
FIGURE 32-3
The InitInv applet
The formula to compute an initial investment is shown here:
Initial Investment = targetValue / (((rateOfRet / compPerYear) + 1) compPerYear * numYears)
where rateOfRet specifies the rate of return, targetValue contains the starting balance, compPerYear
specifies the number of compounding periods per year, and numYears specifies the length of
the investment in years. If you use an annualized rate of return for rateOfRet, then the
number of compounding periods is 1.
The following applet called InitInv uses the preceding formula to compute the initial
investment required to reach a desired future value. The applet produced by this program
is shown in Figure 32-3.
/* Compute the initial investment necessary for
a specified future value.  */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
/*
<applet code="InitInv" width=340 height=240>
</applet>
*/
public class InitInv extends JApplet
implements ActionListener {
JTextField targetText, initialText, periodText,
rateText, compText;
JButton doIt;
double targetValue;
//
original targetValue
double rateOfRet;
//
rate of return
double numYears;
//
length of loan in years
int compPerYear;
//
number of compoundings per year
NumberFormat nf;
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home