# Solved: Getting to a user-defined method



## Statler (Mar 5, 2006)

I am taking a beginners computer science course in Java, and I am currently learning about methods. There is one question where I have to calculate the ending balance on a deposit at a given rate of interest, and it says I need a user defined procedure-type method (called compound), and a main method that will call it.

I just want to know how to get the program to move to the user-defined method because when I run it, it does not output the last statement which gives the ending balance. It only outputs the main method. This is what I have:


```
import java.io.*;

public class CompoundInt {
    
	public static void main (String[] Args) throws IOException {
		
		BufferedReader myInput = new BufferedReader (new InputStreamReader ( System.in));

		String inDeposit, inRate;

    	        System.out.print("Enter your bank balance: ");
    	        inDeposit = myInput.readLine ();
    	
    	        System.out.print("Enter the annual compounded interest rate: ");
    	        inRate = myInput.readLine ();
	  	
    	        compound ();
	}
	
	static public void compound (double deposit, double rate, double endingBalance){
	  	
	  	deposit = Double.parseDouble (inDeposit);
	  	rate = Double.parseDouble (inRate);
	  	
	  	endingBalance = deposit + ((rate/100) * deposit);
	
    	        System.out.println("The ending balance of $" + deposit + " at an annual compounded interest rate of " + rate + "% is $" + endingBalance);
	}
}
```


----------



## Chicon (Jul 29, 2004)

This is an example about using a method :


```
[SIZE=2][B]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CompoundInt {
    
    public static void main(String[] Args) {
        
        BufferedReader myInput = new BufferedReader(new InputStreamReader( System.in));
        String inDeposit, inRate;
        try {
            System.out.println("Enter your bank balance: ");
            inDeposit = myInput.readLine();
            System.out.println("Enter the annual compounded interest rate: ");
            inRate = myInput.readLine();
            double deposit = Double.parseDouble(inDeposit);
            double rate = Double.parseDouble(inRate);
            double endingBalance = compound(deposit,rate);
        } catch (IOException ioe) {                // mandatory
            System.out.println(ioe.getMessage());    
        } catch (NumberFormatException nfe) {      // optional : it's a way to check if the entered
            System.out.println(nfe.getMessage());  // --------   values are numbers  
        }   
    }
    
    static public double compound(double dep, double rt){ // The method returns a double variable
        double result = dep + ((rt/100) * rt);
        System.out.println("The ending balance of $" + dep + " at an annual compounded interest rate of " + rt + "% is $" + result);
        return result;
    }
}
[/B][/SIZE]
```


----------



## Statler (Mar 5, 2006)

That will do! Thanks.


----------

