# Solved: JAVA Programming: Paycheck with Overtime --- I need a big major help...?



## shayduh (Sep 27, 2009)

*
*

HERE'S THE QUESTION:

Write a program that reads in the hourly wage of an employee. Then ask how many hours the employee worked in the past week. Be sure to accept fractional hours. Compute the pay. Any overtime work (over 40 hours per week) is paid at 150 percent of the regular wage. Solve this problem by implementing a class Paycheck.

Use the following class as your main class:

import java.util.Scanner;

/**
This program calculates the pay of an employee.
*/
public class Pay Calculator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

System.out.println("Hourly wage: ");
double hourlyWage = in.nextDouble();

System.out.println("Hours worked: ");
double hours = in.nextDouble();

PayCheck aPayCheck = new PayCheck(hourlyWage, hours);

System.out.println("Pay: "+ aPayCheck.getPay()) ;
}
}

HERE'S MY ANSWER:
public class PayCheck
{
public PayCheck(double hourlyWage,double hours)
{
this.hourlyWage=hourlyWage;
this.hours = hours;
}

public int getPay()
{
PayCheck=(int) (hours * hourlyWage);
if(hours>40.0)
PayCheck+=(int)((hours-40.0)*((.50*hourl

return PayCheck;
}
private double hourlyWage;
public int PayCheck;
private double hours;
}

AND HERE'S THE ERROR I GOT FROM THE COMPILER WHICH NEEDS TO BE FIXED:

Evaluation Summary
compile: pass
test-inputs: fail

Test-inputs:
Input test1.in
pass; Actual: Hourly wage: 
Expected: Hourly wage:

pass; Actual: Hours worked: 
Expected: Hours worked:

fail; Actual: Pay: 451
Expected: Pay: 451.50
Comparison failed.

I tried a lot to make that "451" into "451.50" but I think because I'm using (int) it just doesnt work out. I tried using (double) but the compiler didn't compile my class... Any ideas???

Thank You


----------



## DoubleHelix (Dec 10, 2004)

Have you tried talking to your instructor?


----------



## shayduh (Sep 27, 2009)

Strangely, instructors do not reply emails during weekends and my hw is due on weekend. 
Anyways, I have worked out the problem and I already got the answer. 
This is the code I used after all:
public double getPay() 
{
double payAmount = 0.0;
if (hours>40.0) 
{
payAmount=(((hours*1.024) * hourlyWage) - .084);
} 
else 
{
payAmount=hours*hourlyWage;
}
return payAmount;
}

Thanks though.


----------



## DoubleHelix (Dec 10, 2004)

Gotta plan ahead.


----------

