Jump to content
Sign in to follow this  
alienA2

Wages not calculating correctly

Recommended Posts

Hi My program is not calculating the wages correctly. Can somebody please tell me why??? /** PayCheck Program* This program computes an employee's wages for the week*/import java.util.Scanner;import static java.lang.System.in;import static java.lang.System.out;class mainPayCheckProg{ public static void main(String args[]) { // create an instance of the class or object payCheckMethods aWage = new payCheckMethods(); Scanner prompt_user = new Scanner(in); double payRate; double hours; double wages; int empNum; double max_hours = 40.0; double overtime = 1.5; out.print("Enter Employee Number: "); empNum = prompt_user.nextInt(); out.print("Enter Pay Rate: "); payRate = prompt_user.nextDouble(); out.print("Enter Hours Worked: "); hours = prompt_user.nextDouble(); if (hours > max_hours) { wages = (max_hours * payRate) + (hours - max_hours) * payRate * overtime; } else { wages = max_hours * payRate; } out.print("Employee Number: "); out.println(empNum); out.print("Pay rate: "); out.println(payRate); out.print("Hours worked: "); out.println(hours); out.print("Wages: "); out.println(wages); }}

Share this post


Link to post
Share on other sites
:Unsure: your program is innocent Is the calculating formula correct ?
According to the C++ book I have yes lol :crazy:

Share this post


Link to post
Share on other sites

Try to be even more explicit with the priority of operations, i.e.

wages = (max_hours * payRate) + ((hours - max_hours) * payRate * overtime);

And since this example is derived from a C++ book... try to also be this explicit with C++, and see if the result is the same as the intended one. If the result in ++ is different, this means there's some priority handling missing here, and the intended formula is really

wages = ((max_hours * payRate) + (hours - max_hours)) * payRate * overtime;

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...