Complete the methods in the file Lab9.java The program will be calculating the c
ID: 3730111 • Letter: C
Question
Complete the methods in the file Lab9.java The program will be calculating the compound interest based on an initial balance entered by the user, an annual interest rate, and a number of years to determine the result for. The formula to calculate A, the resultant amount in an account given specific parameters, is given by the following formula: A-P) where r is the annual interest rate as a value between 0.0 and 1.0, n is the number of times the interest is compounded per year (we'll be doing monthly compounding, so this number will be 12), and t is the number of years to compound interest rt There are 3 methods defined in the file that contain no logic. Your task is to complete the logic of those methods to make the program work correctly. The specifications for the methods are in the java file. While you will need to look through the main) method to determine what's going on, you do not need to change anything in the main) method. Just focus on writing the three methods at the end of the file.
Explanation / Answer
public staic double calculate(double P, double r, int t)
{
double ans;
// import java.lang.* to use Math.pow
ans = P * Math.pow(( 1 + r/12 ), (12 * t)); //either this
//else you have to use loop
int res = 1;
for(int i= 0 ; i< 12*t ; i++)
res = res * (1+ r/12);
ans = P * res; //or this
return ans;
}
public static double getDouble(double low, double max)
{
private static Random rand = new Random();
//low inclusive and max exclusive
low = (max-low) * rand.nextDouble() + low;
return low;
}
public static int getInt( int low, int max)
{
private static Random rand = new Random();
//low inclusive and max exclusive
low = rand.nextInt(max-low) + low;
return low;
}