# Pay Calculator & If statement

Stephen Donovn

Greenhorn

Posts: 15

posted 2 years ago

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

[

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

[

posted 2 years ago

First write it down on paper. If someone has worked more than 40 hours, what should he get? How is that calculated?

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

Stephen Donovn

Greenhorn

Posts: 15

posted 2 years ago

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

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

posted 2 years ago

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.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions