Need help: for loop and if statement within a method : I am new to using java and am having some issues in my java class right now and will be needing help with my specific code. I try to look at others questions on here all the time but it's never exactly what I need. Here are my directions:

Create a Java file called CompoundInterestYourLastName.  Write a method called computeBalance( ) that computes the balance of a bank account with a given initial balance and interest rate, after a given number of years. Assume interest is compounded yearly.

Use a loop to control the iterations through the years in your method.

Your method should return a double value.

In your main method, run the following tests to verify your method is working correctly.


System.out.printf("Your total is $%.2f", computeBalance(1000, .045, 3));

// should return $1141.17

I am using eclipse and my only current error is in the comments. I also want some general tips and let me know if my logic is wrong. It probably is. :D

Here is what I have currently although I have been trying different things:



     import java.util.Scanner;
     import java.lang.Math;
     public class CompoundInterestTidwell {

	
	public static void main(String[] args) {
		
		double compInt = computeBalance(1000, 0.045, 3);
		
		System.out.printf("Your new balance is $%.2f", compInt);
		
	}
	       // Getting arror for line of code below. 
           // Error: This method must return a result of type double
	public static double computeBalance(int P, double r, int t) {
		// Formula for compounding interest
		// A = P(1+(r/n))^(n(t))
		// The examples to check my math had rate already divided by 100 so I left out r/n.
		
		for(int c = 0; c <= t; c++ ) {
			// deleted 'n' from equation because it need to equal 1 anyways.
		double compInt = Math.pow(P*(1+r), t);
		 
		if (c < t) {
			c++;
			return compInt;
		}
		
		
	}
	}
    }



Thanks.