How do I Create a Simple Interest Calculator in Java?

Written by kevin walker
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How do I Create a Simple Interest Calculator in Java?
Create your own simple interest calculator in Java. (blue calculator with white numbers image by Nikolay Okhitin from

Interest rates are usually calculated in one of two ways: simple and compound. With simple interest, interest accumulates only on the original amount loaned, while compounded interest uses past interest payments to compute future interest. Many consumer loans use compound interest. However, some loans, particularly mortgages, may use simple interest. You can, in only a few minutes, create a simple Java calculator for simple interest as well as compound.

Skill level:

Things you need

  • Netbeans

Show MoreHide


  1. 1

    Create a new project by clicking "File" and "New Project." Choose "Java application" and name it SimpleInterestCalculator.

  2. 2

    Right-click "SimpleInterestCalculator" and choose "New" and "JFrame Form."

  3. 3

    Right-click the blank form and choose "Add from Palette" and "Label." Repeat this until you have five text labels running down the side of your form. You may need to move some of them around with your mouse to arrange them so they are lined up vertically.

  4. 4

    Right-click the top label and choose "Edit Text." Type "Principle." Repeat this for each label, and give them the following text : Interest Rate, Years, Simple Interest,and Compound Interest.

  5. 5

    Right-click a blank area of the form and choose "Add from Palette" and "TextBox." Repeat until you have five text boxes, one next to each label.

  6. 6

    Right-click the first text box and select "Change Variable Name." Type "principleTextBox." Repeat for each text box, giving them the following names: interestTextBox, yearsTextBox, simpleTextBox, and compoundTextBox.

  7. 7

    Right-click each text box in turn and select "Edit text." Press "Delete" on your keyboard to delete the text in the text box.

  8. 8

    Right-click the form and choose "Add from Palette." Choose "Button." Right-click the button and change its text to "Refresh."

  9. 9

    Double-click the button. This will create an event for the button and move you to it in the source code editor. Paste the following in that location:

        double principle = Double.parseDouble(principleTextBox.getText());
        double interest = Double.parseDouble(interestTextBox.getText()) / 100;
        double years = Double.parseDouble(yearsTextBox.getText());
        simpleTextBox.setText(String.valueOf(principle + (principle * interest * years)));
        compoundTextBox.setText(String.valueOf(principle * Math.pow(1+ interest, years)));

    This calculates simple interest by multiplying the principle, interest, and years and compound interest by raising the interest rate plus one to the power of the number of years and multiplying it by the original principle.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.