import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Sample3 {
public static void main(String args[]){
double amount,iRate,monPay,totalPay;
int years;
String amountStr;
String irateStr;
String yearsStr;
//takes input for loan amount,rate and loan period
amountStr = JOptionPane.showInputDialog(null,"Enter loan amount $ : ");
irateStr = JOptionPane.showInputDialog(null,"Enter % Annual Interest: ");
yearsStr = JOptionPane.showInputDialog(null,"Enter the loan Period; ");
amount = Double.parseDouble(amountStr); //convert input String into double
iRate = Double.parseDouble(irateStr); //convert input string into double
years = Integer.parseInt(yearsStr); //convert input string into integer
monPay = (amount * iRate / 1200) /
( 1 - Math.pow( 1 / ( 1 + iRate / 1200), 12 * years)) ;//calculate monthly payment
totalPay = monPay * 12 * years;
DecimalFormat df = new DecimalFormat("0.00");
System.out.println(df.format(monPay));
JOptionPane.showMessageDialog(null,"your monthly payment is: " + monPay + "\n" +
"your total payment is: " + totalPay );
}
}