This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Pay Calculator & If statement

Stephen Donovn
Greenhorn
Posts: 15
Hi all

4th week into Java and have assignment to work out rate of pay based on hours worked.

rate is 4.60 per hour for 1st hours and then extra payment 4.60 * 1.5 for hours over 40 only.

It's this part I'm having problems with.

My if statement is below but I'm struggling with how I should write the if hours > 40 one.

Hope someone can help.

Thanks

Steve

[

Rob Spoor
Sheriff
Posts: 21088
85
First write it down on paper. If someone has worked more than 40 hours, what should he get? How is that calculated?

Stephen Donovn
Greenhorn
Posts: 15
Thanks for coming back ----

On paper if I worked 50 hours then I'd calculate as follows -

4.60 @ 40 hours = 184

rate at time 1/2 = 4.60 x 1.5 = 6.90

10 hours @ time 1/2 = 69

184 + 69 = 253

I'm trying different variations of the if statement I think needs changing but can't get the sum expected.

Would appreciate any help

Thanks

Steve

Rob Spoor
Sheriff
Posts: 21088
85
You get the calculation correct, so all you need to do is translate that exactly as it is into code. That means your code will need to calculate two sums (for the first 40 hours and for the remaining 10) and add those.

Stephen Donovn
Greenhorn
Posts: 15
Sorry not had chance to reply until now - thanks for the advice .. I think I've figured it out.

Thanks again