Java: interest rate calculator

In this tutorial we will write a simple command line Java program that calculates compound interest rate.

Create new Module (application)


  • File > New Module ...
  • Maven
  • Group ID: org.clc.cit137
  • Artifact: JavaCompoundRateCalc
  • Module Name: JavaCompoundRateCalc
  • Content Root: ~/CLC/2015_spring/JavaCompoundRateCalc
  • Module File Location: ~/CLC/2015_spring/JavaCompoundRateCalc
Create Main.java



Run the program from IntelliJ


for() loop: Year 1; rate $5.0
for() loop: Year 2; rate $10.0
for() loop: Year 3; rate $15.0
for() loop: Year 4; rate $20.0
for() loop: Year 5; rate $25.0
for() loop: Year 6; rate $30.0
for() loop: Year 7; rate $35.0
for() loop: Year 8; rate $40.0
for() loop: Year 9; rate $45.0
for() loop: Year 10; rate $50.0
for() loop: Year 11; rate $55.0
for() loop: Year 12; rate $60.0
for() loop: Year 13; rate $65.0
for() loop: Year 14; rate $70.0
for() loop: Year 15; rate $75.0


while() loop: Year 1; rate $5.0
while() loop: Year 2; rate $10.0
while() loop: Year 3; rate $15.0
while() loop: Year 4; rate $20.0
while() loop: Year 5; rate $25.0
while() loop: Year 6; rate $30.0
while() loop: Year 7; rate $35.0
while() loop: Year 8; rate $40.0
while() loop: Year 9; rate $45.0
while() loop: Year 10; rate $50.0
while() loop: Year 11; rate $55.0
while() loop: Year 12; rate $60.0
while() loop: Year 13; rate $65.0
while() loop: Year 14; rate $70.0
while() loop: Year 15; rate $75.0

Create a new class CompoundRate.java




Change Main.java





Monthly payments if taken for 1 years: $21,344.63 total paid = $256,135.56
Monthly payments if taken for 2 years: $10,911.95 total paid = $261,886.87
Monthly payments if taken for 3 years: $7,436.73 total paid = $267,722.32
Monthly payments if taken for 4 years: $5,700.87 total paid = $273,641.83
Monthly payments if taken for 5 years: $4,660.75 total paid = $279,645.29
Monthly payments if taken for 6 years: $3,968.51 total paid = $285,732.54
Monthly payments if taken for 7 years: $3,475.04 total paid = $291,903.39
Monthly payments if taken for 8 years: $3,105.81 total paid = $298,157.63
Monthly payments if taken for 9 years: $2,819.40 total paid = $304,495.00
Monthly payments if taken for 10 years: $2,590.96 total paid = $310,915.23
Monthly payments if taken for 11 years: $2,404.68 total paid = $317,417.99
Monthly payments if taken for 12 years: $2,250.02 total paid = $324,002.94
Monthly payments if taken for 13 years: $2,119.68 total paid = $330,669.70
Monthly payments if taken for 14 years: $2,008.44 total paid = $337,417.86
Monthly payments if taken for 15 years: $1,912.48 total paid = $344,246.98
Monthly payments if taken for 16 years: $1,828.94 total paid = $351,156.60
Monthly payments if taken for 17 years: $1,755.62 total paid = $358,146.21
Monthly payments if taken for 18 years: $1,690.81 total paid = $365,215.29
Monthly payments if taken for 19 years: $1,633.17 total paid = $372,363.29
Monthly payments if taken for 20 years: $1,581.62 total paid = $379,589.63
Monthly payments if taken for 21 years: $1,535.29 total paid = $386,893.70
Monthly payments if taken for 22 years: $1,493.47 total paid = $394,274.87
Monthly payments if taken for 23 years: $1,455.55 total paid = $401,732.50
Monthly payments if taken for 24 years: $1,421.06 total paid = $409,265.89
Monthly payments if taken for 25 years: $1,389.58 total paid = $416,874.36
Monthly payments if taken for 26 years: $1,360.76 total paid = $424,557.17
Monthly payments if taken for 27 years: $1,334.30 total paid = $432,313.60
Monthly payments if taken for 28 years: $1,309.95 total paid = $440,142.86
Monthly payments if taken for 29 years: $1,287.48 total paid = $448,044.19
Monthly payments if taken for 30 years: $1,266.71 total paid = $456,016.78



Homework: add JavaFX UI to your app

Homework: add another method to calculate amount LEFT at the end of each year if given monthly amount is paid.


As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles