I am new to Java programming and I am struggling and I need help understanding how to write this code for writing a statement public method called calculate interest that accepts account balance and interest rate as arguments. This method should calculate and return the interest by multiplying the two arguments. Thank you in advance for any assistance that can hlp me.

Here is what I came up with below.

public class CalculateInterest {

{
public static void main( String [] args )
{

    public void calculate(int account bal, int rate) {
        double interest = account bal * rate;
         System.out.println("Interest is " + interest);
            }
}

You are on the right track. You already got the result of multiplication between the balance and interest rate. What you need to do are 2 things - 1) return the computed value, and 2) adjust the method to allow the same data type to be returned. This and this should give you the idea how to accomplish what I try to say.

Taywin, I'm afraid you're missing the problem.

he is trying to define a method within a method, which is not allowed in Java.

move your calculcate method out of the main method and call the method while passing the correct parameters.

As stultuske said:
Put your calculate method outside your main method.

Now,

try to avoid space in declaring varible i.e. account bal, instead put account_bal.
create object of the same class, and call your calculate method using that object.
Also change the return type of calculate method with one return statement inside it.

Small point: Java programming conventions prefer the use of "camel case" rather than underscores, so accountBal would be better advice than account_bal.

Oops, I didn't look closely. Thanks stultuske. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.