hey can anyone tell me how to start this with what he\'s given. It\'s been a whi
ID: 3548953 • Letter: H
Question
hey can anyone tell me how to start this with what he's given. It's been a while since i've programed on Eclipse and the way he wrote it out is confusing to me. I dont remember ever seeing anything written like this...
The current balance function, cb(ib, ar, pmt, m) is the current balance on a loan after m months that started with an initial balance of ib, has an annual interest rate ar, a monthly payment of pmt. m should be greater than or equal to 1.
Closely related is the interest accrued function, ia(ib,ar,pmt,m) which is the interest accrued at the end of month m. The function arguments are the same as for the function cb. In fact,
ia(ib,ar,pmt,m) = cb(ib,ar,pmt,m) * ar / 12
The function cb can be computed as follows:
cb(ib,ar,pmt,1) = ib
cb(ib,ar,pmt,m) = cb(ib,ar,pmt,m-1) + ia(ib,ar,pmt,m-1) - pmt if m > 1
In a standard loan, the loan has a term of a certain number of months, we
Explanation / Answer
please rate - thanks
any questions ask
import java.util.*;
public class main
{public static void main(String[] args)
{double ib,ar,pmt,v;
int m;
Random r=new Random();
System.out.println("Trial ib ar m pmt cb");
for(int i=1;i<=20;i++)
{ib=r.nextDouble()*(2000-1000)+1000;
ar=r.nextDouble()*(.2-.05+.05);
m=r.nextInt(11)+5;
pmt=(ar/12.*ib)/(1.-Math.pow(1.+ar/12.,-m));
v=cb(ib,ar,pmt,m+1);
System.out.printf("%d %.2f %.2f %d %.2f %.6f",i,ib,ar,m,pmt,v);
if(Math.abs(v)>Math.pow(10,-5))
System.out.println(" ERROR ERROR ERROR");
else
System.out.println();
}
}
public static double ia(double ib,double ar, double pmt,int m)
{return cb(ib,ar,pmt,m)*ar/12;
}
public static double cb(double ib,double ar, double pmt,int m)
{if(m>1)
return cb(ib,ar,pmt,m-1) + ia(ib,ar,pmt,m-1) - pmt;
else
return ib;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.