File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with methods

 
JackJack Jackson
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Jack






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
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47216
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JackJack,

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

Thanks,
Katrina
 
Sandilya Garimella
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic