Simple Mortgage Calculator

Simple Mortgage Calculator

This example expands on the Monthly Payment Calculator example we posted earlier.

As well as calculating the monthly payment for a loan, it then goes on to use that to calculate the balance of the loan after each payment. This is often referred to as an amortisation schedule.

The displayMonthlyBalance() method handles generating the schedule using a for loop. Each iteration of the loop corresponds to one monthly payment, with the months interest calculated and add to the balance, then the monthly payment deducted from the payment.

for (int i=0; i<termInMonths; i++) {
			
    // Add interest to the balance
						
    // Subtract the monthly payment
						
    // Display running balance
               
}
	
Full source code to our Mortgage Calculator example is available to our members. We include two variations, both with complete source code. The first accepts user input to get the details on the mortgage to calculate amortisation table for. The second reads the mortgage details from a file use the Scanner class. Download the complete source code, and be sure to let us know if you have any questions.
x

10 Responses to “Simple Mortgage Calculator”

  1. John

    How would you display the monthly payment in a popup dialog box instead of to the console?

    • You can use a JOptionPane to achieve that. We are planning a Swing version of this example for a future post that shows how we can use JOptionPane to display the results to the user. Will see if we can raise the priority on that one for you.

  2. Jimmie

    I’m trying this program right now and the Scanner util is now static Scanner console = new Scanner(System.in); I’m currently running and its showing me errors for calculateMonthlyPayment and displayMonthlyBalance. Please update the program.

  3. Jimmie Pierre

    The simple mortgage calculator program code. I’m trying to run it, but its giving me error. Is the code up to date? The does contain two class or one?

  4. How would you do this with requiring user input to get the mortgage, the interest and term??

  5. Sean

    I have the code working but how would I be able to p[lace a time delay between each balance

  6. […] You can find an example of the use of the Scanner class in one our Mortgage Calculator examples. […]

Leave a Reply to Learn Java By Example

s2Member®