Further to the previous answer, your variable types are wrong. In the class
payment
, the only string should be
employeename
, so define:
private String employeename;
private float payhours;
private float workhours;
private float tax;
private float absenthours;
private float paymonth;
I'm not going to give you any code, but I will give you some advice.
Comments are your friend and JavaDoc comments doubly so.
Your names make the code a little hard to read, may I suggest you follow the well established convention of class names beginning with a capital leter, variables and members with lower case, and all subsequent words with a capital; so
Payment
,
employeeName
, etc.
Next up, methods should be verb led, accessors are
float getPayMonth()
twinned with a setter
setPayMonth(float)
.
In a constructor, you should try to avoid calling any member methods.
When accessing a member variable, scope it as
this.payMonth
, class variables as
Payment.taxRate
.
How does all this help? Look at your constructor alone and follow the above:
public class Payment
{
public Payment(String employeeName,
float payHours)
{
this.employeeName = employeeName;
this.payHours = payHours;
}
}
Now you can see what is happening. The more elegant the code the less chance of a problem because it is readable. Sounds 'stoopid' but after 20+ years, I've also found it's true.