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);
2 Years
Discussion Span
Last Post by Taywin

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.

Edited by Taywin


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.


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.