Output

Variable Name     Value in Memory
annualInterestRate
monthlyInterestRate
numberOfYears
loanAmount
monthlyPayment
totalPayment
  1  import java.util.Scanner;
  2  
  3  public class ComputeLoan {
  4    public static void main(String[] args) {   
  5      // Create a Scanner
  6      Scanner input = new Scanner(System.in);
  7  
  8      // Enter annual interest rate
  9      System.out.print("Enter annual interest rate, e.g., 7.25: ");
 10      double annualInterestRate = input.nextDouble();
 11      
 12      // Obtain monthly interest rate
 13      double monthlyInterestRate = annualInterestRate / 1200;
 14  
 15      // Enter number of years
 16      System.out.print(
 17        "Enter number of years as an integer, e.g., 5: ");
 18      int numberOfYears = input.nextInt();
 19      
 20      // Enter loan amount
 21      System.out.print("Enter loan amount, e.g., 120000.95: ");
 22      double loanAmount = input.nextDouble();
 23      
 24      // Calculate payment
 25      double monthlyPayment = loanAmount * monthlyInterestRate / (1
 26        - 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12));
 27      double totalPayment = monthlyPayment * numberOfYears * 12;
 28  
 29      // Display results
 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  }