# How to make a Compound Interest Calculator using Java

## How to make a Compound Interest Calculator using Java

This tutorial deals with how to calculate compound interest in Java. This was given an small assignment to one of my student Abhijit . This  tutorial is idle for those who have just started learning java. In upcoming tutorial I will try to convert this command line application to simple GUI.

## Compound Interest Formula

CI = P (1 + r/n) (nt) – P
where
P = the principal investment amount (the initial deposit or loan amount)
r = the annual interest rate (decimal)
n = the number of times that interest is compounded per year
t = the number of years the money is invested or borrowed for

## Screen shot ## Compound Interest Java Code :

``` import P= Principle, r=Rate (Annual) ,t= Time Period, n= Frequency of calculation in one year.java.util.*; /* * By Abhijit Prasad (Student) * Simple Interest Calculator */ class Compoundinterest{ public static void main(String args[]){ double p,r; int t, n; Scanner inp=new Scanner(System.in); System.out.println("Enter the Principle: "); p= inp.nextDouble(); System.out.println("Enter the Rate: "); r = inp.nextDouble(); System.out.println("Enter the Time Period: "); t=inp.nextInt(); System.out.println("Enter the Frequency: "); n=inp.nextInt(); double ci=compInterest(p,r,t,n); ci = java.lang.Math.round(ci); System.out.println("Calculated Compund Interest: "+ci); } public static double compInterest(double pr, double ra, int t, int freq){ double ci= pr*java.lang.Math.pow(1+ra/(100*freq),freq*t); return ci-pr; } } ```

Subscribe
Notify of This site uses Akismet to reduce spam. Learn how your comment data is processed.