Quantcast

Maximum PC

It is currently Sat Oct 25, 2014 5:49 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Can someone look over this equation for me please?
PostPosted: Tue Mar 11, 2008 7:42 pm 
Malware specialist
Malware specialist
User avatar

Joined: Sun Apr 03, 2005 12:49 pm
Posts: 11696
Location: Kansas City, KS
Hey all, I'm making a Java program for my programming class to calculate payroll.

For overtime (assuming overtime is 40 hours or greater), I'm using the following equation:

Code:
grossPay = (40 * rateOfPay) + ((workHours-40) * rateOfPay * 1.5);



grossPay is just the grossPay, before insurance is taken out
rateOfPay is the amount the person gets paid per hour
workHours is the amount of hours the person works

Did I do this overtime calculation correct? I can supply my full code if needed, I'm just making sure this formula doesn't have any logical errors in it.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 8:02 pm 
7yrs+11,000 Posts
7yrs+11,000 Posts
User avatar

Joined: Tue Jul 27, 2004 5:44 pm
Posts: 11242
Location: The kitten above is not on fire.
It works, assuming the employee puts in at least 40 hours per week. Lets pretend our employee takes a day off, or is only part time. Using that formula for the calculation, he would still be paid for 40 hours, regardless of how much time he actually out in. . Something like this may do you better:
Code:
grossPay = (workhours * rateOfPay) + ((workHours-40) * 1.5);

You'll probably need to add some additional logic in there so you don't end up adding negative numbers to the gross pay.

Another issue you may want to think about is how you are awarding overtime. Correct me if I'm wrong, but dont most employers calculate overtime in daily increments?

Here is a scenario. Lets pretend our employee works mon-wensday normal hours. On Thursday he works 3 hours overtime, and takes off Friday. With your current pay stricture, he wouldn't be paid extra for that overtime he put in on Thursday. Of course, the method for awarding overtime is completely up to you.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 10:20 pm 
Million Club - 5 Plus*
Million Club - 5 Plus*
User avatar

Joined: Sun Sep 12, 2004 6:37 pm
Posts: 4745
Location: In the monkey's litterbox
Hack -- your equation is fine, however gamer's has an error in it.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 2:33 am 
Coppermine
Coppermine
User avatar

Joined: Mon Feb 21, 2005 9:33 am
Posts: 692
Location: Grass Valley, CA
Hackman, your equation is fine, but you need to handle work weeks with less than 40 hours. I'm sure your instructor is sneaky enough to throw a short work week into the data. gamerfreak's equation is not correct, but that looks liek the kind of equation the IRS will use on me come April 15. :wink:


Top
  Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 9:26 am 
7yrs+11,000 Posts
7yrs+11,000 Posts
User avatar

Joined: Tue Jul 27, 2004 5:44 pm
Posts: 11242
Location: The kitten above is not on fire.
smartcat99s wrote:
Hack -- your equation is fine, however gamer's has an error in it.

Blah, I see that. That was at 1:00 AM -- ignore the equation and read the rest. It gives him the right idea, I never meant it to be 100% functional.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 4:00 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24226
Location: Granite Heaven
So long as workHours >= 40, your equation works just fine.

If worksHours < 40, though, you will end up subtracting overtime pay from grossPay for each hour less than 40 .. not a good thing. So, you'll need a conditional statement to ensure correct input or a more robust equation to handle workHours < 40.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 9:26 am 
Malware specialist
Malware specialist
User avatar

Joined: Sun Apr 03, 2005 12:49 pm
Posts: 11696
Location: Kansas City, KS
I probably should have mentioned that I'm using a loop here. (I messed up the spacing of the brackets so just ignore the spacing on them).

It would just normally be a 40 hour work week 5 days a week, 8 hours a day. But some people worked overtime and some worked less than 40.

Sorry if I wasn't more clear to begin with.

Code:
if (workHours < 40)
    {
   grossPay = (workHours * rateOfPay);
     }

   else if (workHours >= 40)
   {
          grossPay = (40*rateOfPay) + ((workHours-40) * rateOfPay * 1.5);
    }


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 9:36 am 
Million Club - 5 Plus*
Million Club - 5 Plus*
User avatar

Joined: Sun Sep 12, 2004 6:37 pm
Posts: 4745
Location: In the monkey's litterbox
If you assume valid input (i.e. non-negative hours worked), then you could simplify it down to this:

Code:
if (workHours < 40) {
    grossPay = (workHours * rateOfPay);
} else {
    grossPay = (40*rateOfPay) + ((workHours-40) * rateOfPay * 1.5);
}


The second if would always return true (with valid input), and then it would save you a conditional check.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 9:51 am 
Malware specialist
Malware specialist
User avatar

Joined: Sun Apr 03, 2005 12:49 pm
Posts: 11696
Location: Kansas City, KS
Will do. Thanks cat.


And thanks to everyone else for the help :)


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 10:27 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Personally, I would recommend losing the if-else structure and replace the 40 with a variable... 40, after all, is a magic number. I believe the French start getting overtime after 20 hours of work, right? And French-Canadians probably after 22 hours. ;)

Code:
int regularWorkHoursPerWeek = 40;
int overtimeHours = Math.max(0, (workHours - regularWorkHoursPerWeek));
grossPay = (workHours * rateOfPay) + (overtimeHours * rateOfPay * 1.5);


The 1.5 is obviously another magic number that should be replaced.

And before someone goes and does it, I didn't suggest removing the if-else block to 'improve performance'. If anybody starts that "It'll save 2 instructions per iteration" crap and I work in a (sur)real-time enviroment where we don't have a nano-second to spare, I'll throw a compiler book at 'em. Not the dragon book either -- one of the lame ones.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.