This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes payroll Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "payroll" Watch "payroll" New topic
Author

payroll

Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13


I have a simple code for payroll. I believe there is a logical error.
When the hourWorked is > 40hrs respecting any payRate I do get a wrong answer.
Look at my attachment for the result giving for 41 hours at 40 dollars per hour payRate.
= 1700 as opposed to 1660. So basically my program is not executing the else if when the
hourWorked is > than 40 hours. I will be glad if someone can help me on this.

One more thing, I will like to have a number of users go into the payroll system and
use the data type for their gross pay. I.E to repeat the process for different employees. I will
also be happy to know how to do it in such way say a specific number of worker can get a grosspay.
Thereafer, the program will stop with ''Goodbye name exiting payroll system now".
or
Now I need to build on it like keep similar data for employees and have the gross pay displayed until there is no more employee data to process. Then I will display "Good Bye."


[Thumbnail for payroll.png]

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

I am not sure if your calculation is right. Let me trace the program for you:
payRate = 40
hoursWorked = 41
grossPay = hoursWorked * payRate = 1640

as hoursWorked is greater than 40:
grossPay += ((hoursWorked-40) * ((payRate*3)/2)) => grossPay = 1640 + ((41-40) * ((40*3)/2)) => grossPay = 1700.

So the result is grossPay = 1700.


Mohamed Sanaulla | My Blog
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
That is so wrong and it frustrated me. In any case I kept trying.


after few changes the if else doesn't execute I get ..... hoursWorked with OT as 40 and the grosspay as 0.0 dolars. Thanks.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

So have you resolved the issue?
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Can you help? I have not resolved the problem.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you need some debugging statements to find out what's going on

add the indicated lines, then try to work out why it prints out what it does

and you can do the same for grosspay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: payroll
 
Similar Threads
Accepting Numeric User Input
Alright, my eyes hurt from staring at this monitor trying to figure this out.
Logic Errors
What is the difference between a double and a float?
DUE AT MIDNIGHT TONIGHT..1 ERROR..HELP