Bank accounts at the First Bank accrue interest that is compounded monthly. For
ID: 3566819 • Letter: B
Question
Bank accounts at the First Bank accrue interest that is compounded monthly. For example, if I deposited $100 at a rate of .05, then after one month I would have (100* .05) = $5 in interest, or $105 total. After two months I would have (105*.05) = $5.25 in interest, giving me $110.25 total. Write a method that inputs the amount deposited, the interest rate, and the number of months and outputs the final total balance in the account. This method should not ask the user for information or print.
Example: accountBalance(100, .05, 1) should give 105, and accountBalance(100, .05, 2) should give 110.25.
public double accountBalance(double start, double rate, int numMonths){
Explanation / Answer
public double accountBalance(double start,double rate,int r){
double total=1;
int i=0;
for(i=1;i<=r;i++){
total=total*(1+rate);
}
total=total*start;
return total;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.