Write a program (in Java) that computes and outputs the monthly payments for a h
ID: 3592918 • Letter: W
Question
Write a program (in Java) that computes and outputs the monthly payments for a home loan. The program prompts the user to input loan amount, interest rate, loan length, and future value of the loan, and outputs the monthly payments. Finish the code
import java.util.Scanner;
public class Lab6Part2 {
/*
the following is a method that computes the monthly payments for a home loan,
based on the amount of the loan, the interest rate, and
the length of the loan (the number of months),
*/
public static double computePayment(double loanAmt, double rate, int numPeriods) {
double monthlyRate = rate / 1200.0;
double partial = Math.pow((1 + monthlyRate), numPeriods) - 1 ;
double denominator = monthlyRate * Math.pow((1 + monthlyRate), numPeriods);
double answer = loanAmt / (partial / denominator);
return answer;
}
public static void main(String[] args) {
/* Prompts the user to input amount of the loan, the interest rate, and
the length of the loan (in months).
Then invoke the computePayment method and output the answer.
*/
}
}
Explanation / Answer
Lab6Part2.java
import java.util.Scanner;
public class Lab6Part2 {
/*
the following is a method that computes the monthly payments for a home loan,
based on the amount of the loan, the interest rate, and
the length of the loan (the number of months),
*/
public static double computePayment(double loanAmt, double rate, int numPeriods) {
double monthlyRate = rate / 1200.0;
double partial = Math.pow((1 + monthlyRate), numPeriods) - 1 ;
double denominator = monthlyRate * Math.pow((1 + monthlyRate), numPeriods);
double answer = loanAmt / (partial / denominator);
return answer;
}
public static void main(String[] args) {
/* Prompts the user to input amount of the loan, the interest rate, and
the length of the loan (in months).
Then invoke the computePayment method and output the answer.
*/
Scanner scan = new Scanner(System.in);
System.out.println("Enter the loan amount: ");
double loanAmt = scan.nextDouble();
System.out.println("Enter the interest rate: ");
double rate = scan.nextDouble();
System.out.println("Enter the length of thee loan (in months): ");
int numPeriods = scan.nextInt();
System.out.println("Payment: "+computePayment(loanAmt, rate, numPeriods));
}
}
Output:
Enter the loan amount:
10000
Enter the interest rate:
12.5
Enter the length of thee loan (in months):
20
Payment: 556.4808105576017
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.