I have the following code for an assignment. Yes, this is for a class, so I don't want the answer given to me but I have searched the code over and I can't come up with anything. A nudge in the right direction would be great.
Thanks for the help.Code:public class Loan {
public float P;
public float I;
public float Ia;
public int Nyr;
public int Nprd;
public void setP() {
P = 200000;
}
public void setI() {
I = 5.75f;
Ia = I/(12*100);
}
public void setN() {
Nyr = 30;
Nprd = Nyr*12;
}
public void CalcTbl() {
float Pa;
int Pc; //current period num
float M; //monthly payment
float Mi; //interest paid
float Mp; //principal paid
Pa = P;
Pc = 0;
for(int Npa = Nprd; Npa = 0; Npa--) { //incompatible data types
Pc ++;
M = Pa * (Ia / (1- power(1+Ia,-1*Npa)));
Mi = Pa * Ia;
Mp = M - Mi;
Pa = Pa - Mp;
System.out.println("Current period " + Pc +
" || Payment $" + M +
" || Interest $" + Mi +
" || Principal $" + Mp);
}
}
public float power (float Base, double Pow) {
float Ans = Base;
for(double x = 2; x > Pow; x++) {
Ans = Ans * Base;}
return Ans;
}
}
public class W2IA {
public static void main(String[] args) {
Loan myLoan = new Loan();
myLoan.setP();
myLoan.setI();
myLoan.setN();
System.out.println("For a loan with:");
System.out.println("Principal amount of " + myLoan.P);
System.out.println("Interest of " + myLoan.I);
System.out.println("Number of periods (months) " + myLoan.Nprd);
myLoan.CalcTbl();
}
}
-RT
