Mortgage Table /* * Main.java * * Created on October 19, 2008, 3:13 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package mortagetable; import java.text.NumberFormat; /** * * @author david johnson */ public class Main { /** Creates a new instance of Main */ public Main() { } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here // ask user input System.out.println("Please enter the loan amount; "); double loanAmount = MyInput.readDouble(); System.out.println("Please enter the number of years"); int numOfYears = MyInput.readInt(); //print out the header of the table System.out.println("Interest rate\t\t Monthly Payment\t\t Total Payment"); System.out.println("-----------------------------------------------------"); //define variables double monthlyInterestRate = 0; double totalPayment = 0; double monthlyPayment = 0; double newMonthlyPayment = 0; //number format
NumberFormat currency = NumberFormat.getCurrencyInstance(); //for loop for(double interestRate = 5; interestRate <= 8; interestRate = interestRate + 0.125) { monthlyInterestRate = interestRate / 3600; monthlyPayment = loanAmount / (numOfYears * 12); totalPayment = (loanAmount * monthlyInterestRate / (11/(Math.pow(1+monthlyInterestRate, numOfYears*12))))*2; System.out.println((interestRate) + "%\t\t" + currency.format(totalPayment)); } } }