• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I call this method?  RSS feed

 
Dustin Boor
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My IDE keeps flagging my code and I don't know whats wrong. I'm a beginner so bare with me, I'm not sure how to call a method with multiple arguments in my parameters. When I try to call employee1.calculatePay(grossPay); its not working which I thought I had to do.

Here is method in my employee class:

Main method:


 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
calculatePay() accepts 3 arguments.
So you cannot call this method like
You are passing only 1 argument.

You need to pass 3 arguments of type int, double and double.
Something like
 
Junilu Lacar
Sheriff
Posts: 11485
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While what Tapas Chand wrote is technically correct, it should be noted that the third parameter defined in the method signature is illogical. The method ostensibly calculates the gross pay. Parameters are normally used for input, not as output, to a method. Only the first two parameters need be defined as arguments to the method. The grosspay parameter can either be a local variable instead or it can be eliminated altogether.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:While what Tapas Chand wrote is technically correct, it should be noted that the third parameter defined in the method signature is illogical...

Oh yes, I should have seen that. Thank you.
 
Paul Clements
Ranch Hand
Posts: 99
1
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:While what Tapas Chand wrote is technically correct, it should be noted that the third parameter defined in the method signature is illogical. The method ostensibly calculates the gross pay. Parameters are normally used for input, not as output, to a method. Only the first two parameters need be defined as arguments to the method. The grosspay parameter can either be a local variable instead or it can be eliminated altogether.

Indeed. In your example grossPay is output, not input. As such, the following would achieve the same result:


If you wanted to call calculatePay and get the grossPay back, then you would do this:

and
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!