Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

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: 20709
68
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: 20709
68
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