Question: 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
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:

For the formula to compute monthly payment, see Listing 2.9, ComputeLoan.java.


Loan Amount: 10000 -Enter Number of Years: 5 PEnter Interest Rate Total Payment 11322.74 11357.13 11391.59 Monthly Payment 188.71 189.29 189.86 5.000% 5.125% 5.250% ... 202.17 202.76 12129.97 12165.84 7.875% 8.000% 1 import java.util.Scanner; 2 3 public class ComputeLoan { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); 4 5 // Enter annual interest rate in percentage, e.g., 7.25% System.out.print("Enter annual interest rate, e.g., 7.25%: "); double annualInterestRate = input.nextDouble(); 10 11 12 13 14 15 16 17 18 19 20 21 22 // Obtain monthly interest rate double monthlyInterestRate =- annualInterestRate / 1200; // Enter number of years System.out.print( "Enter number of years as an integer, e.g., 5: "); int numberOfYears - input.nextInt(); // Enter loan amount System.out.print("Enter loan amount, e.g., 120000.95: "); double loanAmount = input.nextDouble(); 23 // Calculate payment double monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / Math.pow(1 + monthlyInterestRate, numberofYears * 12)); 24 25 26 27 double totalPayment = monthlyPayment * numberoffYears * 12; 28 // Display results System.out.println("The monthly payment is S" + (int) (monthlyPayment * 100) / 100.0); System.out.println("The total payment is S" + (int)(totalPayment * 100) / 100.0); 29 30 31 32 33 34 35 }
Step by Step Solution
3.28 Rating (160 Votes )
There are 3 Steps involved in it
Program plan Crate class called ComputeLoan Declare variables of type double loanAmount ... View full answer
Get step-by-step solutions from verified subject matter experts
