img
FIGURE 32-2
The FutVal applet
Finding the Future Value of an Investment
Another popular financial calculation finds the future value of an investment given the
initial investment, the rate of return, the number of compounding periods per year, and the
number of years the investment is held. For example, you might want to know what your
retirement account will be worth in 12 years if it currently contains $98,000 and has an
average annual rate of return of 6 percent. The FutVal applet developed here will supply
the answer.
To compute the future value, use the following formula:
Future Value = principal * ((rateOfRet / compPerYear) + 1)  compPerYear * numYears
where rateOfRet specifies the rate of return, principal contains the initial value of the
investment, 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 FutVal uses the preceding formula to compute the future
value of an investment. The applet produced by this program is shown in Figure 32-2.
Aside from the computational differences within the compute( ) method, the applet is
similar in operation to the RegPay applet described in the preceding section.
// Compute the future value of an investment.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
/*
<applet code="FutVal" width=380 height=240>
</applet>
*/
public class FutVal extends JApplet
implements ActionListener {
JTextField amountText, futvalText, periodText,
rateText, compText;
JButton doIt;
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home