File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Need help with methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help with methods" Watch "Need help with methods" New topic

Need help with methods

JackJack Jackson

Joined: Apr 18, 2008
Posts: 1
Hello everyone,
I�m new to java and would appreciate any help; I�m trying to put together a program that calculates commission. The program requires me to create a class containing two overloaded methods named computeCommission and three variables. The first method contains two double arguments representing the sales and rate, multiplies them and displays the results. The second method contains a double variable and an int variable representing sales figure and an int commission rate.
This method must divide the commission rate figure by 100.0 before multiplying by the sales figure and displaying the commission . Any and all suggestion would be appreciated.


public class Commission

public static void main(String[] args)


double commRate = 0.07;

double salesFig = 500.00;

int commRate = 7;


public static void computeCommission(double salesFig, double commRate)


commission = salesFig * commRate;

System.out.println("The commission is: " + commission);


public static void computeCommission(double salesFig, int commRate)


doubleComm = commission / 100.0

intComm = salesFig / commRate

System.out.println("The commission is: " + doubleComm + intComm)


marc weber

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

We're here to help, but we won't do the work for you. Can you tell us where exactly you're stuck? Or what your specific questions are?

Maybe the compilation errors would be a good place to start. Do you understand what the error messages are telling you?

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46348
Welcome to the Ranch.

Next time you post, please use the "code" tags below the box; it makes code much easier to read.

Not a good idea to have everything in static methods. Remove static everywhere except before "main" which has to be static.

Try this sort of thing in the main methodYou need to work out how to call the two methods.

In the (double, double) method, you don't declare a type for the "commission" variable. Probably best to have a field called commission, of type double, and don't declare anything in the compute methods.

You can't have two variables in the same method both with the same name (commRate). I would declare your three variables as local variables in the main method.

In the (double, int) method you will get problems with the intComm and doubleComm.
I think you simply want to work out that commission is sales / 100.0 * commRate. Then you just print out commission.

Try that lot; if you have any problems, come back to us.
Katrina Owen

Joined: Nov 03, 2006
Posts: 1367
Hi JackJack,

Please check your private messages for an administrative message from the staff.

Sandilya Garimella

Joined: Apr 17, 2008
Posts: 3

the program code you have written is similar to structured programming i.e C. In Object oriented programming you have to split the problem into two parts its properties or data and methods or procedures that make use of the data provided. the combination of the above two is called as object

i advise to first try to identify objects in your programs that will help you to understand JAVA more...

go through some basic book like Head First JAVA
I agree. Here's the link:
subject: Need help with methods
It's not a secret anymore!