Information to Use The present value of an investment of A dollars for Y years a
ID: 3632218 • Letter: I
Question
Information to UseThe present value of an investment of A dollars for Y years at an annual rate of R percent compounded C times yearly is:
Present Value = A(1 + R/C)YC (1)
Of course, if interest is compounded yearly, C == 1 and (1) simplifies to:
Present Value = A(1 + R)Y (2)
Be careful: in these formulas, only (1 + R/C) is raised to the YC power, A is outside that.
Program to Write
• Write an overloaded method presentValue(…) so that this method implements formulas (1) and (2), using Math.pow(…). Also write a main(…) method that tests both versions.
• The method headers for the presentValue(…) methods are:
double presentValue(double a, int y, double r, int c)
and double presentValue(double a, int y, double r) à c == 1
Optional: the 2nd version of presentValue(…) can call the 1st.
Optional 2: add versions where r is an int, convert it to a percent in the method.
• The main(…) method should try different values for A, Y, R, and (optionally) C, and call both versions of the presentValue(…) method using those.
Explanation / Answer
please rate - thanks
import java.util.*;
public class main
{public static void main(String[] args)
{System.out.println("call parameters=1000,2,5,12 "+presentValue(1000.,2,5,12));
System.out.println("call parameters=1000,2,.05,12 "+presentValue(1000.,2,.05,12));
System.out.println("call parameters=1000,2,5 "+presentValue(1000.,2,5));
System.out.println("call parameters=1000,2,.05 "+presentValue(1000.,2,.05));
}
public static double presentValue(double a, int y, double r, int c)
{return a*Math.pow(1+r/c,y*c);
}
//optional 1
public static double presentValue(double a, int y, double r)
{return presentValue(a,y,r,1);
}
//integer rate optional 2
public static double presentValue(double a, int y, int r, int c)
{return presentValue(a,y,r/100.,c);
}
//integer rate, c omitted optional 2
public static double presentValue(double a, int y, int r)
{return presentValue(a,y,r/100.,1);
}
}