Re: Can this Class be cleaned up at all?



Patricia Shanahan wrote:
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.

Interesting. All I need to do is change the way that the initialSalary is defined in the Employee class and the other classes that extend it should be easy to retrofit. Or will they? What if I have 8 classes that extend Employee and I change the way initialSalary is defined? That means that every class that extends employee and creates a new employee will have to have the call to the constructor changed. Is there a cool way around that? I also have a Manager class that extends Employee. When I create a new Manager I would have to change the way that initialSalary is passed to the construtor. This seems to me to be a bit much.

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.

So you are saying that if I want to create a new employee with a salary of 40,000$ I would have the initialSalary instance variable defined as BigDecimal initialSalary;

So if I wanted to display it via a displayAll method in the class, I would need to divide it by 100 for it to make sense. Something like:

public void displayAll()
{
......
System.out.println("Salary: " + this.initialSalary / 100);
}

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.


I did not know you could do that. Thank you. I am not sure that I understand it though. My constructor only has 4 instance variables. Where are you getting six from? Am I missing something?


Would doing that gain any flexibility that you think you would find
useful in your program?

Patricia
From my consideration of what I am going to use, the EmployeeDoes interface will allow for different types of employees (i.e. managers and directors) to implement methods like takeAVacation differently. If a normal employee wants to take a vacation he/she has to
a) fill out a form
b) book the time
c) get approval

whereas the spec I am working from says that a Director only needs to book the time and it's done. This means to me, that the implementation of a takeAVacation method is different for a director than for a regular employee. Hence, the need for an interface. Make sense?
.



Relevant Pages

  • Re: Factory Class Question
    ... move EmployeeFactory, Employee, Facilty1Employee, and Facilty2Employee all ... Facilty1Employee, and Facilty2Employee as Friend. ... > Facility2_Employee has an overloaded constructor which means I can't make ... >> instance of a class with a private constructor is rare, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Factory Class Question
    ... Jay - thanks for the response. ... I have a base class called Employee ... Facility2_Employee has an overloaded constructor which means I can't make it ... >> Jason MacKenzie ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
    ... No, but imagine a better example that uses a slightly better name, like ... where I have a class representing Employees. ... asking for a new employee, i.e. a new thing of a certain kind. ... my constructor can be called anything: ...
    (comp.lang.perl.misc)
  • Re: classes, strings, learning in VS.NET
    ... > It is a good Compiler, ... > Here you declare that you will provide a constructor for your Employee ...
    (comp.lang.cpp)
  • Re: Can this Class be cleaned up at all?
    ... a well structured class that follows all the good programming guidelines? ... So I am starting out with the low level classes like Employee. ... I have also a class called Manager which extends Employee. ...
    (comp.lang.java.help)