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.