import javax.swing.JOptionPane; import java.text.NumberFormat; class LoanCalculator{ public static void main(String [] args){ int confirm; do{ double principal = Double.parseDouble(JOptionPane.showInputDialog( "Enter Amount you wish to borrow" )); double rate = Double.parseDouble(JOptionPane.showInputDialog( "Enter Annual interest rate (e.g. 6.5):")); int year = Integer.parseInt(JOptionPane.showInputDialog( "Enter number of years")); NumberFormat fmt = NumberFormat.getCurrencyInstance(); System.out.println("The monthly payment is .. " + fmt.format(monthlyPayment(principal, rate, year))); System.out.println("Total Payment " + fmt.format(totalPayment(principal, rate, year))); confirm = JOptionPane.showConfirmDialog( null, "Do Another Computation ?", "Confirmation Dialog", JOptionPane.YES_NO_OPTION); }while(confirm == JOptionPane.YES_OPTION); System.exit(0); }// end main public static double monthlyPayment(double p, double r, int y){ double monthlyRate = r / 12 / 100; int period = y * 12; double numerator = monthlyRate * Math.pow((1 + monthlyRate), period); double denominator = Math.pow((1 + monthlyRate), period) - 1; return p * numerator / denominator; } public static double totalPayment(double p, double r, int y){ return monthlyPayment(p,r,y) * y * 12; } }