Hello,
I've been attempting to write a small application that would compute the monthly payment for a loan. The program should work by requesting the user to input three variables, the loan amount, the interest rate, and the term of the loan in years. I've written a program that I thought would work, though every time I input the data it outputs an incorrect answer. So there must be a problem with my equation; more precisely the way I've attempted to input the equation into the code. I'll admit now, this is an assignment; so I'm not really looking for somebody to do this for me, instead I'd really appreciate some guidance as to where I've gone wrong.
Below I will provide you with my code, and a link to the assignment page with the full equation. I'd appreciate any help you could provide with this; Im just baffled. Thank you.
Assignment Link: http://online.sfsu.edu/~dchao/ISYS350A1F09.htm
import java.util.Scanner;
import java.lang.Math;
public class Homework_1
{
public static void main(String[] args)
{ Scanner sc = new Scanner(System.in) ;
System.out.print("Please enter the loan amount: ");
double LoanAmount = sc.nextDouble();
System.out.print("Please enter the interest rate: ");
double InterestRate = sc.nextDouble();
System.out.print("Please enter the loan term in years: ");
double LoanTerm = sc.nextDouble();
double exponent = (-12 * LoanTerm);
double MonthlyPayment = (LoanAmount * (InterestRate / 12)) / (1 - (1 + (InterestRate / 12)));
double TMP = Math.pow(MonthlyPayment,exponent);
System.out.println();
System.out.println("Your monthly palyment is: " + TMP);
System.out.println();
}
}