/** * Compute the future value of an investment compounded annually. * * * * @author: Anthony Larrain * */ import javax.swing.JOptionPane; import java.text.DecimalFormat; class FutureValue{ public static void main(String [] args) { // input values. String input = JOptionPane.showInputDialog("Enter the amount to invest"); double principle = Double.parseDouble(input); input = JOptionPane.showInputDialog("Enter the annual interest rate (e.g. 6.5)"); double rate = Double.parseDouble(input); input = JOptionPane.showInputDialog("Enter number of years"); int years = Integer.parseInt(input); // Compute the future value double futureValue = principle * (Math.pow( 1 + rate / 100 , years)); // display the result. DecimalFormat fmt = new DecimalFormat("0.00"); System.out.print("$" + principle + " invested at a rate of "); System.out.println(rate +"%" + " for " + years + " years"); System.out.println("Will grow to $" + fmt.format(futureValue)); System.exit(0); } }