I am working on an assignment in which I have to:
Create an Employee class with the following attributes/variables: name age department
Create a class called Department which will contain a list of employees.
a. Department class will have a method which will return its employees ordered by age.
b. Value of Department can be only one of the following:
- "Accounting"
- "Marketing"
- "Human Resources"
- "Information Systems"
I am having the hardest time trying to figure out how to complete 2b. Here is what I have so far:
import java.util.*;
public class Employee {
String name;
int age;
String department;
Employee (String name, int age, String department) {
this.name = name;
this.age = age;
this.department = department;
}
int getAge() {
return age;
}
}
class Department {
public static void main(String[] args) {
List<Employee>empList = new ArrayList<Employee>();
Collections.sort (empList, new Comparator<Employee>() {
public int compare (Employee e1, Employee e2) {
return new Integer (e1.getAge()).compareTo(e2.getAge());
}
});
}
}
" b. Value of Department can be only one of the following: "Accounting" "Marketing" "Human Resources" "Information Systems""-- use an enum type for this property, not a String. This will force Java to only allow specific items of the type for this variable or parameter.