Suppose you want to deposit a certain amount of money into a savings account, and then leave it alone to draw interest for the next 10 years. At the end of 10 years, you would like to have $10,000 in the account. How much do you need to deposit today to make that happen? You can use the following formula, which is known as the present value formula, to find out: The terms in the formula are as follows: • P is the present value, or the amount that you need to deposit today. • F is the future value that you want in the account. (In this case, F is $10,000.) • r is the annual interest rate. • n is the number of years that you plan to let the money sit in the account. Write a method named presentValue that performs this calculation. The method should accept the future value, annual interest rate, and number of years as arguments. It should return the present value, which is the amount that you need to deposit today.
package deposit;
import java.util.Scanner;
public class Deposit {
  public static double principal(double F, double r, double n){
       double results = Math.pow((1+r), n);
       double p = F/results;Â
       return p;
  }
  public static void main(String[] args) {
    System.out.printf("What is the desired future value of the account?: ");
    Scanner scan = new Scanner(System.in);
    double F = scan.nextDouble();
    System.out.printf("What is the annual interest rate?: ");
    double r = scan.nextDouble();
    System.out.printf("For how many years will the money sit in the account? ");
    double n = scan.nextDouble();
    System.out.printf("You need to deposit? %.3f", principal(F, r,n));
    Â
    Â
    Â
    Â
  }
  Â
}
Comments
Leave a comment