• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with methods

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)



}



}
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi JackJack,

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

Thanks,
Katrina
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic