PayCheck class... percision error.. help!
this is a program where you enter the wage and hours you work and it spits out the amount of money you should be receiving.. i am getting a possible loss of percision error.
here is my code
Code :
import java.util.Scanner;
public class PayCheck
{
public PayCheck()
{
Scanner in = new Scanner(System.in);
System.out.println("Wage: ");
double wage = in.nextDouble();
System.out.println("Hours: ");
double hours = in.nextDouble();
}
public int getPayCheck()
{
double pay;
if (hours > 40)
{
pay = (wage*hours)+((hours%40)*(overtime*wage));
}
else
{
pay = wage*hours;
}
return pay;
}
private double hours;
private double overtime = 1.5;
private double wage;
}
thanks
Re: PayCheck class... percision error.. help!
The modulus operator only operates on integers (I think). Also, you're "double adding" the over-forty hours (one copy at standard wage, and another at the overtime wage).
pay = (wage*40) + ((hours-(hours%40)*40)*(overtime*wage))