Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

mprehensive 5.21 Financial application: compare loans with various interest rate

ID: 3607566 • Letter: M

Question

mprehensive 5.21 Financial application: compare loans with various interest rates) Write a program play eight prime numbers per line. Numbers are separated by exactly one space ll the pine humbers between 2 and 1,000, inclusive. Dis- that lets the user enter the loan amount and loan period in number of years, and displays the monthly and total payments for each interest rate starting from 5% to 896, with an increment of I/8. Here is a sample run: Loan Amount: 10000 Enter Number of Years: 5Enter Interest Rate Monthly Payment 5000% 5.125% 5 . 250% Total Payment 188.71 189.29 189.86 11322.74 11357.13 11391.59 7 . 875% 8 . 000% 202.17 202.76 12129.97 12165.84 or the e formula to compute monthly payment, see Listing 2.9, ComputeLoan.java. 5.22 ·( Financial application: loan amortization schedule) The monthly payment for a given t The monthly interest is computed by multiply-

Explanation / Answer


package project;
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class program1 extends Applet implements ActionListener
{
TextField a,b;
public program1()
{   
setLayout(new GridLayout(3, 2, 10, 15));  
setBackground(Color.cyan);

a = new TextField(15);
b = new TextField(15);

b.addActionListener(this);

add(new Label("loan amount")); add(a);
add(new Label("number of years")); add(b);
}
public void actionPerformed(ActionEvent e)
{   
String str1 = a.getText();
double l = Double.parseDouble(str1);
double y = Double.parseDouble(b.getText());
double interest = 5;
System.out.println("interest monthlypayment totalpayment");
/* calculation for monthly and total pay for each interest rate */
while(interest <= 8) {
   double monthlypay = calculateMonthlyPayment(l, y, interest);
   double totalpay = monthlypay * (y * 12);
   System.out.printf("%.3f %.2f %.2f ",interest, monthlypay, totalpay);
   interest = interest + 0.125;
}
}
/* mothod to calculate monthly payment */
public static double calculateMonthlyPayment(double loan, double years, double interest) {
interest /= 100.0;
double monthlyRate = interest / 12.0;
double termInMonths = years * 12;
double monthlyPayment =
(loan*monthlyRate) /
(1-Math.pow(1+monthlyRate, -termInMonths));
return monthlyPayment;
}
}