//Exercise3_14.java: displays the monthly and total payments
//for each interest rate starting from 5% to 8%,
//with an incremental of 1/8.
public class Exercise3_14
{
  // Main method
  public static void main(String[] args)
  {
    int numOfYears;
    double loanAmount;

    // Enter loan amount
    System.out.print("Enter loan amount, for example 120000.95: ");
    loanAmount = MyInput.readDouble();

    // Enter number of years
    System.out.print("Enter number of years: ");
    numOfYears = MyInput.readInt();

    // Display the header
    System.out.print("Interest Rate");
    System.out.print("\t" + "Monthly Payment");
    System.out.println("\t\t" + "Total Payment");

    double monthlyInterestRate;
    double monthlyPayment;
    double totalPayment;

    for (double annualInterestRate = 5.0; annualInterestRate <= 8.0;
      annualInterestRate += 1.0/8)
    {
      // Obtain monthly interest rate
      monthlyInterestRate = annualInterestRate/1200;

      // Compute mortgage
      monthlyPayment = loanAmount*monthlyInterestRate/
        (1-(Math.pow(1/(1+monthlyInterestRate), numOfYears*12)));
      totalPayment = monthlyPayment*numOfYears*12;

      // Display results
      System.out.print(annualInterestRate + "%");
      System.out.print("\t\t" + (int)(monthlyPayment*100)/100.0);
      System.out.println("\t\t\t" + (int)(totalPayment*100)/100.0);
    }
  }
}
