In: Computer Science
Write a program that computes loan payments. The loan can be a car loan, astudent loan, or a home mortgage loan. The program let’s the user enter theinterest rate, number of years, and loan amount, and displays the monthly andtotal payments. in Java.
COP 2510
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
import java.util.Scanner;
public class LoanPayments
{
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        // ask the data here
        System.out.print("Enter loan amount: ");
        double loanAmount = scanner.nextDouble();
        System.out.print("Enter interest rate: ");
        double interestRate = scanner.nextDouble();
        interestRate=interestRate/100;
        System.out.print("Enter number of years: ");
        double numOfYears = scanner.nextDouble();
        // Calculate the loan
        double numofMonths=numOfYears*12;
        double monthlyPayment = ( loanAmount *interestRate*(Math.pow((1+interestRate),numofMonths))) / (Math.pow((1+interestRate),numofMonths)-1);
        System.out.println("\nMonthly Payments= "+monthlyPayment);
        // total payments = num of months * monthly payments
        double totalPayments = monthlyPayment * numofMonths;
        System.out.println("Total Payments= "+totalPayments);
    }
}
===========
SCREENSHOTS:

OUTPUT:


