# calculating Bank interest rate.

• 05-10-2008, 04:22 PM
dotnet007
calculating Bank interest rate.
I want to solve interest rate calculation of a Bank.
But i don't know about the algorithm of interest rate calculation for bank.
suppose one customer has a account. ha has 5000US in his account for five month.
so how can i calculate the total interest of 5 months (suppose, monthly interest rate is 0.05 )
Please if any body know about interest calculation of a bank help me...
• 05-10-2008, 05:44 PM
sukatoa
Algorithm? You should know that before converting it to java code.

You can search from the web about it.

come back here and post the algorithm that you have.
• 05-10-2008, 07:21 PM
dotnet007
thanks for your reply. i will post the algorithm if i can manage....
Best of Luck
• 05-12-2008, 09:09 AM
Eku

For Annual Interest Rates:
totalAmmount = (BasicAmmount) x ((InterestRateAnnually)^(NumberOfYears))
or in another algo it may look like this. But they are the same.
for (int i-0; i<NumberOfYears; i++){
basicAmmount = (BasicAmmount) + (BasicAmmount * InterestRateAnnually)}

Code:

```double CurrMoney=5000,TotalMoney; int years = 5; for (int i=0;i<years;i++){ CurrMoney=CurrMoney + (CurrMoney*0.05); } TotalMoney=CurrMoney;```
OR the simplified version
Code:

```double CurrMoney=5000,TotalMoney; int years = 5; TotalMoney=CurrMoney * (1+((0.05)^years));```
• 05-12-2008, 10:03 AM
Eranga
Much better to avoid loops as much as possible. The second way is much better.
• 05-13-2008, 02:11 AM
Eku
The 2nd one is much simplier. Just search on how to use the Exponent. i think '^' doesnt work. =P
• 05-13-2008, 04:34 AM
Eranga
Yes it is. For exponent you can't use ^ sign. It's just for pseudo codes. If you it's not work, why you put it there ;)

Use Math class for those types of processing.
• 05-13-2008, 04:55 AM
Eku
Thanks for the Tip. Here it is now.
Code:

```double CurrMoney=5000,TotalMoney; int years = 5; TotalMoney=CurrMoney * (1+(java.lang.Math.pow((0.05),years)));```
• 05-13-2008, 05:06 AM
Eranga
Yep it's. But it is not good to import Java packages in runtime. Import them before use, at the top level of any class.
• 05-13-2008, 09:08 AM
Eku
Thanks for the tips Eranga. Here is the New Code. =)
Code:

```package test; import java.lang.Math.*; public class Main {     public static void main(String[] args)         {             double CurrMoney=5000,TotalMoney,years = 5;             TotalMoney=CurrMoney * (1+(Math.pow((0.05),years)));             System.out.println(TotalMoney);         } }```
• 05-13-2008, 09:30 AM
Eranga
Ya, it's much better.