# Mortgage Calculator week 5 Java II

Essay by skysharkUniversity, Bachelor'sA+, February 2009

download word file, 1 pages 1.0 1 reviews

Downloaded 1999 times

/*Programmer:SkySharkFile:MortgageCalculator5.javaDate:June 23,2008Purpose:To calculate and display the mortgage of the hard coded terms- 7 year at 5.35%- 15 year at 5.5%- 30 year at 5.75%*/import java.text.NumberFormat; //for currency formatimport java.util.*; //for Scannerimport static java.lang.System.out;import java.io.*;public class MortgageCalculator5{public static void main (String [] args)throws IOException{double loanAmount = 200000; //Loan amountdouble monthlyInt[] = {5.35, 5.50, 5.75}; //Monthly interest ratedouble monthlyPayment = 0; //Monthly paiddouble payments = 0;//Paymentdouble interestpaid = 0;//Interest paiddouble principalpaid = 0;//Principal paiddouble interest = 0;//Interestint loanTerm[] = {7, 15, 30}; //Term in year, arrayint lineCount = 1;// Int line countNumberFormat currency = NumberFormat.getCurrencyInstance (); //for currency formatScanner sc = new Scanner(System.in); //for reading in a value from the keyboardint choice = 1; //Int Choice// terminate if number 4 is picked or invalid entry, otherwise continue programwhile ( choice != 4 ) //start loop for choice 4{do {if (choice > 4 || choice 4 );if ( choice != 4 ){switch (choice) { // branch to an appropriate selectioncase 1:loanAmount = 200000.00;

// reset loan amountlineCount = 1; //reset line countmonthlyPayment = calculate(loanAmount, monthlyInt[0], loanTerm[0]) ;out.println("\nYour monthly payment will be: " + currency.format (monthlyPayment) + "\n");out.printf("%s%15s%20s%20s\n", "Payment#", "Balance", "Principle Paid", "Interest Paid");while (lineCount key to continue ...\n");System.in.read(); //read in}}break;case 2:loanAmount = 200000.00; // reset loan amountlineCount = 1; //reset line countmonthlyPayment = calculate(loanAmount, monthlyInt[1], loanTerm[1]) ;out.println("\nYour monthly payment will be: " + currency.format(monthlyPayment) + "\n");out.printf("%s%15s%20s%20s\n", "Payment#", "Balance", "Principle Paid", "Interest Paid");while (lineCount key to continue ...\n");System.in.read(); //read in}}break;case 3:loanAmount = 200000.00; // reset loan amountlineCount = 1; //reset line countmonthlyPayment = calculate(loanAmount, monthlyInt[2], loanTerm[2]) ;out.println("\nYour monthly payment will be: " + currency.format(monthlyPayment) + "\n");out.printf("%s%15s%20s%20s\n", "Payment#", "Balance", "Principle Paid", "Interest Paid");while (lineCount key to continue ...\n");System.in.read(); //read in}}break;}out.println();out.println();}else //choice 4 was selectedout.println("\nThank You and come to see us again.\n");} // end of while} // end of mainpublic static double calculate(double Amount, double MonthInt, int Term) // calculation{double Monthly;Term = Term * 12;MonthInt = MonthInt / 100 / 12;Monthly = ( Amount * Math.pow((1 + MonthInt), Term) * MonthInt) /( Math.pow( (1 + MonthInt), Term ) - 1 );return Monthly;}private static void ShowMenu() // menu setup{out.println(" M E N U");out.println("\n");out.println("1. 7 Years at interest rate 5.35%");out.println("2. 15 Years at interest rate 5.50%");out.println("3. 30 Years at interest rate 5.75%");out.println("4. End program \n");out.print("\nEnter your choice: ");} // end function ShowMenu} // end of class