
Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest rate, number of years, loan amount, and displays the monthly and total payments. (using GUI input) use (import javax.swing.JOptionPane)

import javax.swing.*;
import java.text.*;
public class CalculateLoan{
public static void main(String[] args) {
DecimalFormat df=new DecimalFormat("##.##");
double payment=0, interestrate=0, loanamount=0, years=0;
loanamount = Double.parseDouble(JOptionPane.showInputDialog(null,"Loan Amount:"));
interestrate = Double.parseDouble(JOptionPane.showInputDialog(null,"Interest Rate:"));
years = Double.parseDouble(JOptionPane.showInputDialog(null,"Number of Years:"));
if(interestrate > 1){
interestrate = interestrate / 100;
}
payment = (interestrate * loanamount / 12) / (1.0 - Math.pow(((interestrate / 12) + 1.0), (-(12 * years))));
System.out.println("Loan Amount:\t" + loanamount);
System.out.println("Interest Rate:\t" + (df.format(interestrate * 100)) + "%");
System.out.println("Number of Years:\t" + years + " (Months: " + years * 12 + ")");
System.out.println("The Monthly Payment:\t" + (df.format(payment)));
System.out.println("The Annual Payment:\t" + (df.format(payment*12)));
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.