Jump to content

Wages not calculating correctly


alienA2

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); }}

Link to comment
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;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...