Another newbie question...
Hi,
Well, I have a mulitplication problem, so it seems. The program reads the right values for the variable empHours and empRate. However when i try to calculate earnings, the result is $0.00...Here is the code...What am I missing? Shouldn't this be pretty straightfoward? Here is the output of the program...
The initial parameters are:
The employee's name is: Paul
Paul worked 4.0 hours this week.
Paul's hourly rate is 1.0
Paul earned $0.00 this week.
Press any key to continue . . .
publicclass empinfo
{
private String empName;//Employee name for this class
privatedouble empHours;
privatedouble empRate;
//constructor initializes name
public empinfo( String name,double hours,double rate)
{
empName = name;
empHours = hours;
empRate = rate;
}
// method to set the empName
publicvoid setEmpName( String name )
{
empName = name;//store the empName
}//end method
//method to set empHours
publicvoid setempHours (double hours )
{
empHours = hours;//store empHours
}//end method
//method to set empRate
publicvoid setempRate (double rate )
{
empRate = rate;// store empRate
}//end method
//method to retrieve empRate
publicdouble getEmpRate()
{
return empRate;
}//end method
// method to retirev empHours
publicdouble getEmpHours()
{
return empHours;
}//end method
// method to retrieve empName
public String getEmpName()
{
return empName;
}//end method
//method to calculate earnings
publicdouble earnings = empHours * empRate;
//method to retrieve earnings
publicdouble getEarnings()
{
return earnings;
}
// Display the employee info
publicvoid displayInfo()
{
System.out.printf("The employee's name is: %s\n", getEmpName() );
System.out.printf("%s worked %s hours this week.\n", getEmpName(), getEmpHours() );
System.out.printf("%s's hourly rate is %s\n", getEmpName(), getEmpRate() );
System.out.printf("%s earned $%.2f this week.", getEmpName(), getEarnings() );
}//end method displayInfo
}//end class empinfo

