我对 Java 和一般编程非常陌生,并且我有一个评估要完成,我将员工(具有姓名、年龄和部门属性;部门只能是四个枚举值之一)加载到对他们进行排序的程序中按年龄并判断年龄是否为质数。该作业需要 Company、Department 和 Employee 类。我相信我可以计算出年龄/主要成分——我知道如何在谷歌上搜索算法。我正在努力解决的是将所有离散的部分组合成一个有凝聚力的整体。
这是我到目前为止所拥有的。我已经安排了一名员工,但我这样做的方式似乎完全不优雅且效率低下。我确信有更好的方法,但我遇到了心理障碍。
编辑:正如下面指出的,我不清楚。我正在寻求帮助的是填充数据结构。
公司等级:
public class Company {
static Employee one = new Employee();
public static void main(String[] args) {
one.setName("Counting Guru");
one.setAge(55);
one.setDepartment(DepartmentList.ACCOUNTING);
}
}
部门列表类:
import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
public enum DepartmentList {
ACCOUNTING, MARKETING, HUMANRESOURCES, INFORMATIONSYSTEMS;
public static void main(String[] args) {
Map<DepartmentList,String>
enumMap=new EnumMap<DepartmentList,String>(DepartmentList.class);
enumMap.put(DepartmentList.ACCOUNTING, "Accounting");
enumMap.put(DepartmentList.MARKETING, "Marketing");
enumMap.put(DepartmentList.HUMANRESOURCES, "Human Resources");
enumMap.put(DepartmentList.INFORMATIONSYSTEMS, "Information Systems");
Set<DepartmentList> keySet = enumMap.keySet();
for (DepartmentList department : keySet) {
String value = enumMap.get(department);
System.out.println("ENUMMAP VALUE:"+value);
}
}
}
员工等级:
public class Employee {
String empName;
int empAge;
DepartmentList empDept;
Employee() {
}
public String getName() {
return empName;
}
public void setName(String name) {
this.empName = name;
}
public int getAge() {
return empAge;
}
public void setAge(int age) {
this.empAge = age;
}
public DepartmentList getDepartment() {
return empDept;
}
public void setDepartment(DepartmentList department) {
this.empDept = department;
}
public Employee(String empName, int empAge, DepartmentList empDept){
}
}
我也有一个部门类,但它目前是空的。
我在正确的轨道上吗?有人可以轻推我一下吗?谢谢!