Financial application compare loans with various interest ra

Financial application: compare loans with various interest rates) 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:

Solution

Solution:

compareLoansWithInterestRates.java

import java.util.Scanner;

public class compareLoansWithInterestRates
{
   public static void main(String[] args)
   {
       // Create a Scanner
        Scanner input = new Scanner(System.in);

       // Enter loan amount
       System.out.print(\"Enter loan amount:\");
       double loanAmount = input.nextDouble();

       // Enter number of years
        System.out.print(\"Enter number of years: \");
        int numberOfYears = input.nextInt();

        // Enter yearly interest rate start value
       double annualInterestRate = 5.0;

        // Printing table header
        System.out.printf(\"Interest Rate \\t Monthly Payment \\t Total Payment \ \");

       while (annualInterestRate <= 8.0)
       {
           // Obtain monthly interest rate
           double monthlyInterestRate = annualInterestRate / 1200;

           // Calculate payment
           double monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12));
            double totalPayment = monthlyPayment * numberOfYears * 12;

            // Display results
            System.out.printf(\"%-18.3f%-18.2f%-18.2f\ \", annualInterestRate,
monthlyPayment, totalPayment );

            annualInterestRate = annualInterestRate + 1.0 / 8;
        }
   }
}

SampleOutput:Enter loan amount:5000
Enter number of years: 5
Interest Rate Monthly Payment Total Payment
5.000 94.36 5661.37
5.125 94.64 5678.57
5.250 94.93 5695.80
5.375 95.22 5713.06
5.500 95.51 5730.35
5.625 95.79 5747.67
5.750 96.08 5765.03
5.875 96.37 5782.42
6.000 96.66 5799.84
6.125 96.95 5817.29
6.250 97.25 5834.78
6.375 97.54 5852.30
6.500 97.83 5869.84
6.625 98.12 5887.43
6.750 98.42 5905.04
6.875 98.71 5922.68
7.000 99.01 5940.36
7.125 99.30 5958.07
7.250 99.60 5975.81
7.375 99.89 5993.58
7.500 100.19 6011.38
7.625 100.49 6029.22
7.750 100.78 6047.09
7.875 101.08 6064.99
8.000 101.38 6082.92

 Financial application: compare loans with various interest rates) Write a program that lets the user enter the loan amount and loan period in number of years a
 Financial application: compare loans with various interest rates) Write a program that lets the user enter the loan amount and loan period in number of years a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site