私は次のことをしなければならない課題に取り組んでいます。
次の属性/変数を持つ Employee クラスを作成します: name age department
従業員のリストを含む Department というクラスを作成します。
を。部門クラスには、従業員を年齢順に返すメソッドがあります。
b. Department の値は、次のいずれかになります。
- 「会計」
- "マーケティング"
- "人事"
- 「情報システム」
2b を完了する方法を理解するのに最も苦労しています。これが私がこれまでに持っているものです:
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());
}
});
}
}