Re: Can this Class be cleaned up at all?
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Sat, 24 Feb 2007 19:03:59 -0800
John T wrote:
private float initialSalary;
float is almost always the wrong type. It only has the equivalent of 24
significant bits, less than 8 significant digits. That means the cents
figure of a high annual salary might be in danger.
Either BigDecimal, or an integer count of cents (or other minimal
currency unit), works well. If you really need floating point operations
on your salaries, use double.
public Employee(int employeeNumber, String employeeName, Calendar date, float initialSalary) {
this.employeeNumber = employeeNumber;
this.employeeName = employeeName;
this.initialSalary = initialSalary;
this.hireDate = date.getTime();
}
You could use:
this(employeeNumber, employeeName, date, initialSalary, 0);
instead of the method body. That makes it easier to see that it is doing
the same thing as the six argument constructor, but with the salary left
zero.
....
Is there anything that can be changed to make it look less clunky? I was thinking about making it an interface and having it implemented but when I thought about the IS-A HAS-A guideline I thought it would make more sense to have the Employee class and an interface called EmployeeDoes to encapsulate the methods.
Would doing that gain any flexibility that you think you would find
useful in your program?
Patricia
.
- Follow-Ups:
- Re: Can this Class be cleaned up at all?
- From: John T
- Re: Can this Class be cleaned up at all?
- References:
- Can this Class be cleaned up at all?
- From: John T
- Can this Class be cleaned up at all?
- Prev by Date: Re: Unchecked compiler warning
- Next by Date: Re: Can this Class be cleaned up at all?
- Previous by thread: Re: Can this Class be cleaned up at all?
- Next by thread: Re: Can this Class be cleaned up at all?
- Index(es):