{"id":96,"date":"2010-06-05T10:46:21","date_gmt":"2010-06-05T00:46:21","guid":{"rendered":"https:\/\/learn-java-by-example.com\/?p=96"},"modified":"2015-11-20T17:57:34","modified_gmt":"2015-11-20T06:57:34","slug":"simple-mortgage-calculator","status":"publish","type":"post","link":"https:\/\/learn-java-by-example.com\/java\/simple-mortgage-calculator\/","title":{"rendered":"Simple Mortgage Calculator"},"content":{"rendered":"

This example expands on the Monthly Payment Calculator example<\/a> we posted earlier.<\/p>\n

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.<\/p>\n

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.<\/p>\n

\r\nfor (int i=0; i<termInMonths; i++) {\r\n\t\t\t\r\n    \/\/ Add interest to the balance\r\n\t\t\t\t\t\t\r\n    \/\/ Subtract the monthly payment\r\n\t\t\t\t\t\t\r\n    \/\/ Display running balance\r\n               \r\n}\r\n\t\r\n<\/pre>\n
\nFull 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<\/a>. Download the complete source code<\/a>, and be sure to let us know if you have any questions.
\nx<\/span><\/div>\n","protected":false},"excerpt":{"rendered":"

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…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[24,4],"tags":[25,9,10,26,6,8,12,11],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6Yyl2-1y","jetpack-related-posts":[{"id":56,"url":"https:\/\/learn-java-by-example.com\/java\/monthly-payment-calculator\/","url_meta":{"origin":96,"position":0},"title":"Monthly Payment Calculator","date":"June 2, 2010","format":false,"excerpt":"This is the simplest form of one of the classic problems given to first year Java students. It aims to get you comfortable with the structure of a simple Java application and how to get input from the user. User input in this example is taken from the console (standard\u2026","rel":"","context":"In "Java"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":98,"url":"https:\/\/learn-java-by-example.com\/java\/calculator-keypad\/","url_meta":{"origin":96,"position":1},"title":"Calculator Keypad","date":"August 14, 2010","format":false,"excerpt":"This problem involves understanding some of the basics of building a Swing application including how individual components are laid out inside a window, and how your application can react to the user interacting with the application. In this case we need to update a text field whenever a button is\u2026","rel":"","context":"In "Java"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":339,"url":"https:\/\/learn-java-by-example.com\/java\/scanner-read-words-text-file\/","url_meta":{"origin":96,"position":2},"title":"Using Scanner to read words from text file","date":"November 20, 2014","format":false,"excerpt":"Often you need to read a file line by line. Alternatively sometimes you want to read text word by word (for example to count the occurrence of different words). The Scanner classes next() method can be used for this as shown in the following example. You can find an example\u2026","rel":"","context":"In "Java"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":160,"url":"https:\/\/learn-java-by-example.com\/java\/pascals-triangle\/","url_meta":{"origin":96,"position":3},"title":"Pascals Triangle","date":"February 13, 2011","format":false,"excerpt":"Write a Java application that prints the first 10 lines of Pascals Triangle. Each row of a Pascals Triangle can be calculated from the previous row so the core of the solution is a method that calculates a row based on the previous row which is passed as input. Once\u2026","rel":"","context":"In "Java"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":222,"url":"https:\/\/learn-java-by-example.com\/java\/list-array\/","url_meta":{"origin":96,"position":4},"title":"Using a List instead of an array","date":"March 8, 2012","format":false,"excerpt":"Lists and arrays can both be used to store ordered collections of data. Both have their strengths and weakness which we shall discuss in a later post. Previously we showed you how to generate Pascals Triangle and in that Java example we used arrays to represent each row of the\u2026","rel":"","context":"In "Java"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":355,"url":"https:\/\/learn-java-by-example.com\/java\/printing-triangles-java\/","url_meta":{"origin":96,"position":5},"title":"Printing Triangles in Java","date":"November 23, 2015","format":false,"excerpt":"A common problem many new Java developers is to write a program that prints out a triangle. There a lots of variations on this problem but lets start with a simple case and then have a look at some possible variations. Probably the simplest case is a left aligned triangle\u2026","rel":"","context":"In "Featured"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/posts\/96"}],"collection":[{"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":9,"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":361,"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/posts\/96\/revisions\/361"}],"wp:attachment":[{"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn-java-by-example.com\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}