
Calculate Interest
On my BankAccount program one of the method should calculate interest as below.
Calculate interest: The interest is compounded daily and is calculated as follows
IN = P(1 + i)n – P (n is power, I could not make it as power visually in here)
Where
IN is interest
P is Principle
i is the daily percentage rate calculated as yearly interest / 365
n is the number of days(I make it 30 on my program to calculate monthly interest)
User will enter the balance and annual interest rate. Here is my method and result. I could not apply this formula to my method correctly because my result in not correct. If you guys give me a hand that I will appreciate you.
Code:
//Interest Calculation
public void interest()
{
interest = balance * Math.pow((1 + annualInterestRate/365), 30) balance;
}
Code:
Enter Your Name:
john
Enter Your Account Number:
35
Enter Your Begining Balance
200
Enter Your Deposit
100
Enter Your Withraw
200
Enter the Annual Interest Rate
10
Account Holder Name: john
Account Number 35
[COLOR="Red"]Account Balance: 100.0
Daily Interest Rate 0.0273972602739726
Monthly Interest 124.98424052172155
Account Balance after Interest Added 224.98424052172155[/COLOR]
Process completed.

What is the value & variable type of annualInterestRate? (Note that it should be a double, otherwise its division by 365 may result in undesired rounding.)

value is 10 and data type is double

If you want it to be a 10% annual interest rate, then its value should be 0.1, not 10.0. When using 10, I get the same number as your program. When using 0.1, I get $0.825191... which seems right.

Thanks I was assuming when I put 10 it was 10% however i was wrong, so when I enter 0.1 I have correct value