Hi everyone, I'm new here and new to Java (I guess this is how all newbies start their threads )
Anyway, I have to make a program that will calculate present value. We have to do the calculations in a separate function and my code will nonot run properly.
The formula for this is P = F/ (1 + R)^n
Where P = the present value they must invest now. F is the future value of what they want their investment to accumulate to, and N is the number of years they plan to keep it invested.
Any help would be greatly appreciated.
import java.util.Scanner; public class project2 { public static void main(String[] args) { System.out.println("This program will determine present value."); displayValue(P); System.out.println("You will need to invest " + P + " to reach your desired future value."); } public static void displayValue(double P) { double rate; double future; double years; double P; //create a scanner object for keyboard input Scanner keyboard = new Scanner(System.in); System.out.print("Please enter the annual interest rate: "); rate = keyboard.nextDouble(); system.out.print("Please enter what you want the future value to be: "); future = keyboard.nextDouble(); System.out.print("Please enter the amount of years you will keep money in account: "); years = keyboard.nextDouble(); firstExp = (1 + rate); secondValue = Math.pow(firstExp,years); P = future/secondValue; } }