• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructors  RSS feed

 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep getting a zero dollar return when I run my main. I am multiplying grossPay by hours but something is not catching. Please help . Thanks

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
erik pierce wrote:Also I cannot figure out how to post code properly in this forum.


See UseCodeTags

Welcome to the Ranch.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You have not called setGrossMethod() to set the value that's why it is taking 0 value.
 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you elaborate on that. Where am I supposed to call the setGrossPay method?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


you are passing 'gp' parameter but not using it there is no use of it. Anyway you can call it in main itself



or in calculate grossPay in the constructor itself..

io
 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Your welcome.
 
Chris Barrett
Bartender
Posts: 321
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi erik,

Actually, since grossPay is a calculated value I would suggest you don't bother storing it at all. It's a waste of system resources to store something that is calculated.
Consider just having a getGrossPay method that returns the calculated value of hours * pay;

Oh, and is your employee's hourly pay rate storing that rate in pennies? As you are using an int for the class variable pay, an hourly pay rate of $10.95 cannot be stored (the value would be rounded to $11). you should consider either using a double type or using more descriptive variable names that clarify the unit increments. For example, hourlyPayInCents or hourlyPayInDollars . It's important to make variable names as clear as possible to help humans read your code. For a real world example of what can happen when unit increments are not clearly defined between programmers, please review Mars Climate Orbiter - a $125,000,000 lost NASA project because the unit increment was not clearly defined.

Cheers!
Chris
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!