/**
* The file name is ComputeLoan.java.
* Calculate the total loan payment.
*/
Import javax.swing.jooptionpane;
Public computer {
//main method
Public static void main(String [] agrs) {
//Enter the annual interest rate.
string anunanalinterestratestring = joptionpane . showinputdialog(" Please input "+
"Annual interest rate, e.g. 7.8");
//Converts a string to double precision.
double annualInterestRate = double . parse double(anunalInterestRateString);
//Convert annual interest rate into monthly interest rate.
double monthly interestate = annual interestate/ 1200;
System.out.println ("annual interest rate is"+annual interest rate);
System.out.println ("monthly interest rate is"+monthly interest ");
//Enter the number of years
string numofyearstring = joptionpane . showinputdialog(" Please input "+
"Number of years, e.g. 5");
//Convert a string to an integer
int numOfYears = integer . parse int(numofyearstring);
System.out.println ("number of years is"+numofyears);
//Enter the total loan amount
String totalloaninput = jooptipane.showinputdialog ("Please enter the total loan amount"+
",such as 9899888.2");
//The string to be converted with double precision.
double total loan = double . parse double(totalLoanInput);
System.out.println ("total loan is"+total loan ");
//Calculate the total monthly payment.
double total monthly payment = total loan * monthly interestate/
( 1- 1/(math . pow( 1+monthly interest,numOfYears * 12)));
double total yearly payment = total monthly payment * 12 * numOfYears;
//format reserves two digits after the decimal point.
totalMonthlyPayment =(int)(totalMonthlyPayment * 100)/ 100.0;
totalYearlyPayment =(int)(totalYearlyPayment * 100)/ 100.0;
//Display the results
String output = "Monthly payment is \n"
+Total Monthly Payment+"\ nThe total loan payment is \ n"
+total yearly payment;
joptionpane . showmessagedialog(null,output);
}
}