我正在尝试编写一个程序,该程序必须检索存储在Array中的员工列表。我的代码看起来像这样;
package Assignment2;
import java.util.Scanner;
public class employeeTest {
public static void main(String []args)
{ Scanner in = new Scanner(System.in);
int menuSel;
System.out.println("Menu");
System.out.println("1. Display all staff");
System.out.println("2. Clear Schedule");
System.out.println("3. Display Schedule");
System.out.println("4. Assign shifts to casual employees");
System.out.println("5. Assign shifts to permanent employees");
System.out.println("6. Calculate total weekly wages");
System.out.println("7. Exit program");
menuSel = in.nextInt();
switch(menuSel){
case 1:
}
}
public static void employeeList(Employeeclass _list[])
{//this is the array that stores the employees
_list[0] = new permanentEmployee("Joshua", "Power", "POW30310713", 5, 812.47);
_list[1] = new casualEmployee("Joshua", "Power", "POW12345678", 5, 812.47, 56.00);
_list[2] = new casualEmployee("Robyn", "Power", "ROB12345678", 3, 5.0, 00.00);
_list[3] = new permanentEmployee("Joshua", "Power", "POW12345678", 5, 812.47);
_list[4] = new permanentEmployee("Joshua", "Power", "POW12345678", 5, 812.47);
_list[5] = new casualEmployee("Robyn", "Power", "ROB12345678", 3, 5.0, 00.00);
_list[6] = new casualEmployee("Joshua", "Power", "POW12345678", 5, 812.47, 23.0);
_list[7] = new casualEmployee("Robyn", "Power", "ROB12345678", 3, 5.0, 00.00);
_list[8] = new casualEmployee("Robyn", "Power", "ROB12345678", 3, 5.0, 00.00);
_list[9] = new casualEmployee("Robyn", "Power", "ROB12345678", 3, 5.0, 00.00);
}
public static void listEmployees(Employeeclass _list[])
{
for (int i=0; i<_list.length; i++)
System.out.println(_list[i].toString());
}
{
Employeeclass list[] = new Employeeclass[10];
employeeList(list);
listEmployees(list);
}
}
答案 0 :(得分:0)
此解决方案意味着您已检索到未分类的员工列表。它是所有员工的列表或临时员工列表。
看一下java.util.Comparator类。在这种情况下使用它。事实上,java.util.Collections有一个方法可以使用一个(https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html#sort(java.util.List,%20java.util.Comparator))进行排序。
您可以根据自己喜欢的任何类属性进行排序。