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

Project: Comparing Loans Problem Description: Write a program that lets the user

ID: 638752 • Letter: P

Question

Project: Comparing Loans

Problem Description:

Write a program 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 8%, with an increment of 1/8. Here is a sample run:

Loan Amount: 10000

Number of Years: 5

Interest Rate Monthly Payment Total Payment

5%           188.71          11322.74

5.125%       189.28          11357.13

5.25%    189.85          11391.59

...

7.875%       202.17          12129.97

8.0%         202.76          12165.83

Hint:

Can you get the first four rows manually? This will help you understand how to compute the numbers mathematically.

Can you write a program to produce the first four rows? This will help you see the pattern.

Can you generalize it in a loop to produce all the rows?

Finally, format the output correctly.

     Double rate;

    rate= rate/1200;

   double x=(1 + rate)^ms

   mp=(rate+ rate/(x -1))*p

Explanation / Answer

import java.util.Scanner;
import java.lang.Object;

public class Loan_Calc {

public static void main(String[] args) {
double numer;
double denom;
double b, e;
double numYears;
double principal;
Scanner in = new Scanner(System.in);

System.out.println("Loan Amount: ");
principal = Double.parseDouble(in.nextLine());
System.out.println("Number of Years: ");
numYears = Double.parseDouble(in.nextLine());
System.out.println("Interest Rate | Monthly Payment | Total Payment");


for ( double intRate = 5; intRate <= 8; intRate = Math.round((intRate + .125) * 1000.0)/1000.0 ) {
numer = intRate/100.0 * principal / 12;
e = -(12 * numYears);
b = (intRate/100.0 / 12) + 1.0;
denom = 1.0 - Math.pow(b, e);
System.out.println( intRate + "% | $" + Math.round((numer / denom)*100.0) / 100.0 + " | $" + Math.round(((numer / denom) * 12 * numYears) * 100.0) / 100.0);
}
}
}