The code is as follows:
Calculate loan
Package Classdemo;
Import Javax.swing.joptionpane;public class Computeloan {
public static void Main (string[] args) {
User Input Loan Total
String loanstring = Joptionpane.showinputdialog ("Please enter the total amount of the loan:");
Double loanamount = double.parsedouble (loanstring);
User input Annual interest rate
String annualintereststr = Joptionpane.showinputdialog ("Please enter the loan annual interest rate (e.g. 7.00):");
Double annualinterestrate = double.parsedouble (ANNUALINTERESTSTR);
Calculate monthly interest Rate
Double monthlyinterestrate = annualinterestrate/1200;
User input loan years
String numberofyearsstr = Joptionpane.showinputdialog ("Please enter the length of the loan:");
int numberofyears = Integer.parseint (NUMBEROFYEARSSTR);
Calculate monthly repayment Amount and total repayment amount
Double monthlypayment = Loanamount * Monthlyinterestrate/(1-1/Math.pow (1 + monthlyinterestrate, Numberofyears * 12)) ;
Double totalpayment = monthlypayment * numberofyears;
Format payment as two digits after the decimal point, using a downward rounding method
monthlypayment = (int) (monthlypayment * 100)/100.0;
totalpayment = (int) (totalpayment * 100)/100.0;
Output results, totalpayment and Monthlypayment
String output = "Monthly repayment amount:" + monthlypayment + "\ n Total Repayment amount:" + totalpayment;
Joptionpane.showmessagedialog (null, Output);
}
}
A simple Java Loan program