/** * Title: Chapter 2, "Primitive Data Types and Operations" * Description: Examples for Chapter 2 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // ComputeMortgage.java: Compute mortgage payments public class ComputeMortgage { /**Main method*/ public static void main(String[] args) { double annualInterestRate; int numOfYears; double loanAmount; // Enter yearly interest rate System.out.print( "Enter yearly interest rate, for example 8.25: "); annualInterestRate = MyInput.readDouble(); // Obtain monthly interest rate double monthlyInterestRate = annualInterestRate/1200; // Enter number of years System.out.print( "Enter number of years as an integer, for example 5: "); numOfYears = MyInput.readInt(); // Enter loan amount System.out.print("Enter loan amount, for example 120000.95: "); loanAmount = MyInput.readDouble(); // Calculate payment double monthlyPayment = loanAmount*monthlyInterestRate/ (1 - 1/(Math.pow(1 + monthlyInterestRate, numOfYears*12))); double totalPayment = monthlyPayment*numOfYears*12; // Display results System.out.println("The monthly payment is " + monthlyPayment); System.out.println("The total payment is " + totalPayment); } }