/**
 * 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 MortgageTable
{
  /**Main method*/
  public static void main(String[] args)
  {
    //declare variables
    double annualInterestRate;
    double loanAmount;
    int numOfYears;
    

     // Enter number of years
    System.out.println("Please input number of years: ");
    numOfYears = MyInput.readInt();
    
    // Enter loan amount
    System.out.println("Please input the loan amount: ");
    loanAmount = MyInput.readDouble();
    
    System.out.println("Interest Rate\t"+"Monthly Payment\t"+"Total Payment");
    System.out.println("-----------------------------------------------------");	
 
    // For loop
    double monthlyInterestRate;
    double monthlyPayment;
    double totalPayment;
    for (annualInterestRate=5.0;
         annualInterestRate<=8.0;
         annualInterestRate=annualInterestRate+0.125)
    {
 
       monthlyInterestRate = annualInterestRate / 1200;
       
    // Calculate monthly payment
  	monthlyPayment = 
  	   loanAmount*monthlyInterestRate/(1-1/(Math.pow(1+monthlyInterestRate, numOfYears*12)));

      
    //calculate total payment  
     totalPayment = monthlyPayment * numOfYears * 12;
    
     
    // Display monthly payment and totalPayment
    System.out.println(annualInterestRate+"%\t\t"
       +(int)(monthlyPayment*100)/100.0+"\t\t\t"
       +(int)(totalPayment*100)/100.0);
    }
  }
}