You are on page 1of 2

Future Investments

/*
* Main.java
*
* Created on September 27, 2007, 4:14 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package futureinvestmenttable;
import java.text.*;

/**
*
* @author instructor
*/
public class Main {

/** Creates a new instance of Main */


public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// ask user input
System.out.println("Please enter the investment amount:");
double investmentAmount = MyInput.readDouble();
System.out.println("Please enter the number of years:");
int numOfYears = MyInput.readInt();

//define variables
double futureValue = 0;
double monthlyInterestRate = 0;

//prepare formatting outside the loop


NumberFormat valueFormat = NumberFormat.getCurrencyInstance();
// print out the header
System.out.println("Interest Rate\t\tFuture Value");
System.out.println("---------------------------------------");

// start the loop


for(double annualInterestRate = 6; annualInterestRate<=10;
annualInterestRate=annualInterestRate+0.5)
{
//calculate monthly interest rate
monthlyInterestRate = annualInterestRate / 1200;
//calcualte future value
futureValue = investmentAmount * Math.pow(1+monthlyInterestRate,
numOfYears*12);
//display result
System.out.println(annualInterestRate + "%\t\t\t"
+valueFormat.format(futureValue));
}
}

You might also like