0
votes

From a previous question I asked on enums, I was able to understand what enums really are, but I'm still very new to them in practicing. In my lab, it unexpectedly says:

"Create class Manager which extends class SalariedEmployee and contains the following information:

-The name of the department being managed by this employee. Create an enumerated class with the 4-8 different departments such as Payroll, Production, Accounting, Research, Marketing, etc.

-Number of employees (an integer) – a value between 1 and 100. "

Would it seem to you guys if I'm doing this correctly? :

public enum Department {
Payroll(10), Production(25), Accounting(30), Research(25), Marketing(7);
//DepartmentName(numberOfEmployees)
private int numberOfEmployees;

private Department(int numberOfEmployees) {
    this.numberOfEmployees = numberOfEmployees;
}

}

Do you guys think this is valid and sufficient? Obviously the professor knows for sure what he's asking of, but from your own interpretation, am I doing this correct?

Also, If my super constructor's validation range for an int is a bigger range than the one I want the specific parameter for my subclass to have, would just issuing an if/else statement after the super() call be sufficient? For example:

  public SalariedEmployee(String name, String number, double salary, double deductions) {
    super(name, number);
    if (salary >= 40000.00 && salary <= 160000.00) {
        this.yearlySalary = salary; 
    } else {
        this.yearlySalary = 75000.00;

BUT in the subclass I want the range to be between 40k-100k, so I did this:

     public Supervisor(String name, String number, double salary, double deductions, int goals) {
    super(name, number, salary, deductions);
    if (salary >= 40000.00 && salary <= 100000.00) {
        this.yearlySalary = salary; 
    } else {
        this.yearlySalary = 75000.00;
    }

    }

Is that sufficient enough to override the super constructor's argument range/specifications? Thank you.

2

2 Answers

1
votes

I doubt that the teacher intends for you to put the number of employees into the enum. Additional info provided to enums is usually data that is not subject to change. The number of employees is something that changes frequently. I believe the requirement of your instructor says that the Manager class should include a property that states how many employees are managed by the Manager, something like this:

public class Manager extends SalariedEmployee {
    private Department department;
    private Integer numEmployees;
...
}

Since this appears to be an assignment, I don't want to give too much more code than this. Good luck!

I think what you are asking in the second part of your question is sufficient. After calling super() in your constructor, you are free to change the values of any of the properties set by the super() method to different values. I'm not sure I fully understand what you are trying to do with the salary ranges, but I think you have given enough information to say that what you are doing is sufficient.

1
votes

All you really need to put in your subclass constructor is

super(name, number, salary,deductions);
if(salary>100000.00){
    this.yearlySalary=75000.00;
}

because you are aleady checking if it is between 40000 and 160000 in your superclass. Your enum looks to be correct.