private double earnings= hours *wage;
This is not like excel, don't expect the value to be recalculated each time hours
or wage
change.
Because the default value for a double is 0.0, that's why earnings
is equals to 0.0.
You have to initialize this value after you initialized hours
and wage
, most likely in your constructor:
public HourlyEmployee( String first, String last,double payMe,
double hourlyWage, double hoursWorked ){
super( first, last );
setWage( hourlyWage ); // validate and store hourly wage
setHours( hoursWorked ); // validate and store hours worked
payMe = earned();
earnings= hours *wage;
}
But I'm trying exactly that , that is that the value would be recalculated every time hours or wage change
As suggested in the comments, you can get rid of the earnings
variable and return the value in the getPaymentAmount
method
@Override
public double getPaymentAmount() {
return hours*wage;
}