Example: Future Value of an Investment

A couple starts setting aside $30,000 a year when they are 45 years old. They expect to earn 5% interest on the money compounded yearly. The future value of the investment is computed for a 20 year period.
import com.imsl.finance.*;
import java.text.NumberFormat;

public class fvEx1 {
    public static void main(String args[]) {
        double rate = .05;
        int nper = 20;
        double payment = -30000.00;
        double pv = -30000.00;
        int when = Finance.AT_BEGINNING_OF_PERIOD;
        
        double fv = Finance.fv(rate, nper, payment, pv, when);
        System.out.println("After 20 years, the value of the investments " +
        "will be " + NumberFormat.getCurrencyInstance().format(fv));
    }
}

Output

After 20 years, the value of the investments will be $1,121,176.49
Link to Java source.