• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pay Calculator & If statement

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

[

 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry not had chance to reply until now - thanks for the advice .. I think I've figured it out.

Thanks again
 
reply
    Bookmark Topic Watch Topic
  • New Topic