Need help java code(with Detailed comment ), and run completely. The program sho
ID: 3905634 • Letter: N
Question
Need help java code(with Detailed comment), and run completely.
The program should request information from the user in the following format
thank you!
Methods and Method Overloading (150 pts.) You will write the Java code for a program that uses a method to calculate the monthly payment for a loan. The formula for calculating a payment is shown further down. This application will produce a list of possible loan payments based on a series of annual interest rates starting with a user entered starting annual interest rate which is incremented in a loop until it reaches a user entered ending annual interest rate. The rate will be incremented by an increment rate which the user also enters In summary the user will need to enter A starting annual interest rate such as 4.000%, which is the decimal value 0.0400 An ending annual interest rate such as 6.000%, which is the decimal value 0.0600 The rate by which the starting rate will increment as it progresses towards the ending rate such as 0.25% which is the decimal value 0.0025 The first number of years over which the loan will be repaid such as 15 The last number of years over which the loan will be repaid such as 30 The number of years by which the starting term will increment as it progresses towards the ending term such as 5 a loan amount such as 100,000 dollars . - - - - - The main method will Acquire input from the user Invoke the payment calculation method within a loop - s program requires nested loops- an outer loop controlled by controlled by the Hint: thi interest rate as it progresses from the stating rate to the ending and an inner loop rate the term as it progresses from the stating term to the ending term. It will calculate the payment and display them from inside the inner loop Since the user enters annual rates and the number of years for the loan, the program will need to convert the annual values to monthly values: Calculate the monthly interest rate, which we'll abbreviate as mir (monthly interest rate), as the annual rate divided by 12 Calculate the numbers of months over which the loan will be repaid, which we'll abbreviate as mtp (months to pay), as the number of years times* 12 - - Here's how to calculate a loan payment Annuity Factor -(mir*(1+mir)Amtp)/(((1+mir)Amtp)-1) Assuming a 30 year loan for $180,000 and an annual rate of 0.0375 (3.75%)the results of substituting the values in the formula are Annuity Factor(0.003125*(1+0.003125)A360)/(1+0.003125A360)-1)Explanation / Answer
Given below is the code for the question.
import java.util.Scanner;
public class CalculatePayment {
public static double getPayment(double loanAmt, double annualRate, int term)
{
double mir= annualRate / 100 / 12;
int mtp = term * 12;
double annuityFactor , payment;
double numerator, denominator;
numerator = mir * Math.pow(1 + mir, mtp);
denominator = Math.pow(1+mir, mtp) - 1;
annuityFactor = numerator / denominator;
payment = loanAmt * annuityFactor;
return payment;
}
public static void main(String[] args) {
double startRate, endRate, incrRate;
double loanAmt;
int startYears, endYears, incrYears;
double payment;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the starting annual interest rate as a percent (n.nn): ");
startRate = keyboard.nextDouble();
System.out.print("Enter the ending annual interest rate as a percent (n.nn): ");
endRate = keyboard.nextDouble();
System.out.print("Enter the annual interest rate increment as a percent (n.nn): ");
incrRate = keyboard.nextDouble();
System.out.print("Enter the first term in ears for calculating payments: ");
startYears = keyboard.nextInt();
System.out.print("Enter the last term in ears for calculating payments: ");
endYears = keyboard.nextInt();
System.out.print("Enter the term increment in years: ");
incrYears = keyboard.nextInt();
System.out.print("Enter the loan amount: ");
loanAmt = keyboard.nextDouble();
System.out.println("Payment schedule");
for(double rate = startRate; rate <= endRate; rate += incrRate)
{
System.out.printf("%10.4f", rate);
for(int term = startYears ; term <= endYears; term += incrYears)
{
payment = getPayment(loanAmt, rate, term) ;
System.out.printf("%10.2f", payment);
}
System.out.println();
}
}
}
output
====
Enter the starting annual interest rate as a percent (n.nn): 4.00
Enter the ending annual interest rate as a percent (n.nn): 6.00
Enter the annual interest rate increment as a percent (n.nn): 0.25
Enter the first term in ears for calculating payments: 15
Enter the last term in ears for calculating payments: 30
Enter the term increment in years: 5
Enter the loan amount: 100000
Payment schedule
4.0000 739.69 605.98 527.84 477.42
4.2500 752.28 619.23 541.74 491.94
4.5000 764.99 632.65 555.83 506.69
4.7500 777.83 646.22 570.12 521.65
5.0000 790.79 659.96 584.59 536.82
5.2500 803.88 673.84 599.25 552.20
5.5000 817.08 687.89 614.09 567.79
5.7500 830.41 702.08 629.11 583.57
6.0000 843.86 716.43 644.30 599.55
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.