Output
Variable Name   Value in Memory
1 import java.util.Scanner;
2
3 public class ComputeLoan {
4 public static void main(String[] args) {
5
6 Scanner input = new Scanner(System.in);
7
8
9 System.out.print("Enter annual interest rate, e.g., 7.25: ");
10 double annualInterestRate = input.nextDouble();
11
12
13 double monthlyInterestRate = annualInterestRate / 1200;
14
15
16 System.out.print(
17 "Enter number of years as an integer, e.g., 5: ");
18 int numberOfYears = input.nextInt();
19
20
21 System.out.print("Enter loan amount, e.g., 120000.95: ");
22 double loanAmount = input.nextDouble();
23
24
25 double monthlyPayment = loanAmount * monthlyInterestRate / (1
26 - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12));
27 double totalPayment = monthlyPayment * numberOfYears * 12;
28
29
30 System.out.println("The monthly payment is $" +
31 (int)(monthlyPayment * 100) / 100.0);
32 System.out.println("The total payment is $" +
33 (int)(totalPayment * 100) / 100.0);
34 }
35 }