Answer to Question #56326 in Java | JSP | JSF for Ridwan

Question #56326
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
1
Expert's answer
2015-11-18T04:09:27-0500
import java.util.Scanner;
public class Question {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter loan amount:");
double loanAmount = input.nextDouble();
System.out.print("Enter number of years: ");
int numberOfYears = input.nextInt();
double annualInterestRate = 5.0;
System.out.printf("%-18s%-18s%-18s\n", "Interest Rate",
"Monthly Payment", "Total Payment");
while (annualInterestRate <= 8.0) {
double monthlyInterestRate = annualInterestRate / 1200;
double monthlyPayment = loanAmount
* monthlyInterestRate
/ (1 - 1 / Math.pow(1 + monthlyInterestRate,
numberOfYears * 12));
double totalPayment = monthlyPayment * numberOfYears * 12;
System.out.printf("%-18.3f%-18.2f%-18.2f\n", annualInterestRate,
monthlyPayment, totalPayment);
annualInterestRate = annualInterestRate + 1.0 / 8;
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS