import java.util.Scanner;
import java.text.NumberFormat;

public class FutureValueApp
{
   public static voice main(String[] args)
   {
     Scanner sc = new Scanner(System.in);
     String choice = "y";

     while (!choice.equalsIgnoreCase("n"))
     { 
       // get the input from the user
       System.out.print("Enter monthly investment: ");
       double monthlyInvestment = sc.nextDouble();
       System.out.print("Enter yearly investment interest rate: ");
       double interestRate = sc.nextDouble();
       System.out.print("Enter number of years: ");
       int years = sc.nextInt();
       
       // converts yearly to monthly values and initialize future value
       double monthlyInvestment = interestRate/12/100;
       int months = years * 12;
       double futureValue = 0.0;

       // call the future value method
       double futureValue = calculateFutureValue(monthlyInvestment, monthlyInterestRate, months);
       
       // format and display the result
       NumberFormat currency = NumberFormat.getCurrencyInstance();
       System.out.println("Future value: "
                          + currency.format(futureValue));
       System.out.println();

       // see if the user wants to continue
       System.out.print("Continue? (y/n): ");
       choice = sc.next();
       System.out.println();
     }

   }

  // a static method that requires three argument and returns a double 

  private static double calculateFutureValue(doble monthlyInvestment, double monthlyInterestRate, int months)
  {
     double futureValue = 0.0;
     for (int i = 1; i <= months; i++)
     {
        futureValue = (futureValue + monthlyInvestment) * (1 + monthlyInterestRate);

     }
     return futureValue;
  }

}
Site hosted by Angelfire.com: Build your free website today!