Create a Java Mortgage Payment Calculator - Full Tutorial

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • Complete Java course: codingwithjohn...
    Source code here: www.codingwith...
    Let's create a Mortgage Payment Calculator in Java!
    Calculating a Mortgage payment seems complicated, but it's not so bad when you break it down. Calculating a mortgage payment is a great beginner Java program to write, since you're taking in user input, and doing some simple calculations, then printing out the mortgage payment result. As a bonus, we'll also produce the full mortgage payback amount!
    Learn or improve your Java by watching it being coded live!
    Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java developers.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletria...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Phone I use for recording:
    amzn.to/3HepYJu
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com...
    ☕Complete Java course:
    codingwithjohn...
    codingwithjohn...

КОМЕНТАРІ • 32

  • @shreyashkar9407
    @shreyashkar9407 2 роки тому +4

    Thank you so much sir for this very easy to understand video not only I understood the code but at the same time I now know how to find the mortgage on paper 😂......keep up the good work and keep these kind of small projects coming in....🤘❤️

  • @dolgoonamartaivan7268
    @dolgoonamartaivan7268 2 роки тому +2

    Thank you so much, great tutorial. Keep going!

  • @lesegoleso4918
    @lesegoleso4918 2 роки тому +1

    This is the 1st video I watch from you and I love this channel already 😂🖤
    What shortcut did you use to get the Import Scanner part? I always type it out.

    • @CodingWithJohn
      @CodingWithJohn  2 роки тому +1

      In Eclipse, ctrl + shift + O will organize imports

    • @lesegoleso4918
      @lesegoleso4918 2 роки тому

      @@CodingWithJohn Thanks mate. 💯

  • @awesomebearaudiobooks
    @awesomebearaudiobooks 9 місяців тому +1

    I wrote the code exactly as you did and I get this error after entering the annual interest rate:
    Enter the annual interest rage:
    .04
    Exception in thread "main" java.util.InputMismatchException
    at java.base/java.util.Scanner.throwFor(Scanner.java:939)
    at java.base/java.util.Scanner.next(Scanner.java:1594)
    at java.base/java.util.Scanner.nextFloat(Scanner.java:2496)
    at javalearning/mortgagecalculator.Main.main(Main.java:23)
    My scanner is written just like yours:
    System.out.println("Enter the annual interest rage:");
    float annualInterestRate = scanner.nextFloat();
    Why is this so? The program itself works if I divide by 100:
    System.out.println("Enter the annual interest rage:");
    float annualInterestRate = scanner.nextFloat() / 100;
    But I DO want to be able to work with amounts like .04, so how can I fix this?

  • @designwithgeet7895
    @designwithgeet7895 3 роки тому +1

    once again best tutorial

  • @thomas_m3092
    @thomas_m3092 2 роки тому +1

    Very nice video. Thank you.
    Could you do it as a GUI ?

  • @kwerksickle
    @kwerksickle 2 роки тому

    Thank you so much for this video you have saved my day!

  • @andymorales5718
    @andymorales5718 3 роки тому +1

    So helpful !! Thank you :D

  • @phatttin6753
    @phatttin6753 Рік тому

    Thank you so much sir 😍

  • @stuckintha90s
    @stuckintha90s 2 роки тому

    Thank you very much 🙂

  • @kunalkheeva
    @kunalkheeva 2 роки тому

    you are the best ❤️

  • @nahomegirma3596
    @nahomegirma3596 2 роки тому

    Love this video!!! Im trying to add Property tax & home owner insurance calculating code but having hard time ! Can you please help ?

  • @mikelawry07
    @mikelawry07 3 роки тому +1

    Sir you are the Mafia in Java. I don’t want to miss any tutorial of your . Please give me the link of your course, I don’t mind to pay .

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому

      I'm thrilled you enjoy the videos, thanks so much for watching!
      The link to the course is in each video description, but here it is again: codingwithjohn.thinkific.com/courses/java-for-beginners
      There's a listing there of all the lessons and what they cover so you're not surprised by what it covers, and even a few free preview lessons. I'll be adding more to that course in the future as well, and anyone who gets it will have access to all current and future content forever.

  • @bigtimetechnology3249
    @bigtimetechnology3249 Рік тому

    Thanks : )

  • @wristdisabledwriter2893
    @wristdisabledwriter2893 3 роки тому +1

    I’m having trouble with json files and android. I would love to see you do a video on json

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому

      I haven't done a ton with Android applications, but I work with JSON every day. Is it mostly just serializing objects into JSON, and deserializing JSON strings back into objects? Or is there some other aspect?

    • @wristdisabledwriter2893
      @wristdisabledwriter2893 3 роки тому

      I’m trying to make a quiz app and unfortunately my teacher insisted on json files to get the questions and answers. I don’t know what serialize means. Can you tell me that too

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому +1

      Serializing is when you take a java object and translate it into some format to be saved outside of the program, typically into a file or database as some type of string representation. So for example you can serialize an object into JSON in a file. Deserializing is the other way, where you take some stored info, such as from a DB or file, and make an object out of it.
      I'm not sure I'll be able to get to making a video about all that and it may not apply well to your specific situation anyway, but we use a library called Jackson at work to do our JSON serialization and deserialization. It may not help at all with your project unfortunately, but it's what I'm familiar with.

    • @wristdisabledwriter2893
      @wristdisabledwriter2893 3 роки тому

      @@CodingWithJohn thanks I think telling me the information is more important

  • @Luna-tl9xh
    @Luna-tl9xh 2 роки тому

    How would we calculate the total interest?

  • @Ehrenization
    @Ehrenization 3 роки тому +1

    hmm my monthly payment ended up being -96666.6664etc monthly. Do you have an idea why that would be?

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому +1

      Hmm well I'd certainly love to have a payment where the bank pays me almost $100,000 per month... But yeah, something has to be wrong. If you want you can paste in your code, and what numbers you're entering, and I (or your fellow viewers) can have a look and see if we can find out what might not be right.

    • @Ehrenization
      @Ehrenization 3 роки тому

      ​@@CodingWithJohn yeah for sure!
      package com.ehrenlearnsjava;
      import java.sql.SQLOutput;
      import java.util.Scanner;
      public class Main {
      private static final int MONTHS_IN_A_YEAR = 12;
      public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      System.out.println("Enter the principal amount:");
      double principal = scanner.nextDouble();
      System.out.println("enter the annual interest rate:");
      float annualInterestRate = scanner.nextFloat();
      System.out.println("enter the term in years");
      int termInYears = scanner.nextInt();
      float monthlyInterestRate = annualInterestRate / MONTHS_IN_A_YEAR;
      int numberOfPayments = termInYears * MONTHS_IN_A_YEAR;
      double monthlyPayment = principal * (
      monthlyInterestRate * (Math.pow(1 + monthlyInterestRate, numberOfPayments)) /
      (Math.pow(1 + monthlyInterestRate, numberOfPayments)) - 1);
      System.out.println("Monthly payment: " + monthlyPayment);

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому +5

      I figured out what's wrong with yours - it looks like your parentheses are off in your payment calculation. The way the parentheses are arranged in this program is very important, and if they're not just right, the whole calculation can be thrown off.
      If you replace your calculation with this, it should work great:
      double monthlyPayment = principal * (
      (monthlyInterestRate * (Math.pow(1 + monthlyInterestRate, numberOfPayments))) /
      ((Math.pow(1 + monthlyInterestRate, numberOfPayments)) - 1)
      );

    • @Ehrenization
      @Ehrenization 3 роки тому +4

      @@CodingWithJohn Wow thank you! I just made the adjustments and it worked, now I know to keep a more watchful eye on those perentheses. I really appreciate the time you put in to answering my question!

  • @nathanielbriones6997
    @nathanielbriones6997 3 роки тому

    how to see the principal ammount?

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому

      The principal amount is one of the inputs the user puts in. You can't calculate the mortgage payment without having the principal amount already.

  • @nathanielbriones6997
    @nathanielbriones6997 3 роки тому

    i did not see principal ammount?

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому

      We collect it from the user on line 13 in the program, then use it in the calculation on line 24/25 (depending on where you are in the video).