import java.util.*; // Test out the list of workers, show Arrays.sort public class WorkerListTest { public static void main(String args[]) { WorkerList list = new WorkerList(); // build a small list of workers Worker w = new Worker("zander", 20); boolean success = list.append(w); if (!success) { /* handle error */ } w = new Worker("dickey", 10); success = list.append(w); if (!success) { /* handle error */ } w = new Worker("mouse"); success = list.append(w); if (!success) { /* handle error */ } w = new Worker("duck"); success = list.append(w); if (!success) { /* handle error */ } // display unsorted list System.out.println("Unsorted List:"); list.display(); System.out.println(); // sort and display sorted list list.sortList(); System.out.println("Sorted List:"); list.display(); } } //---------------------------- WorkerList ---------------------------------- class WorkerList { private Worker [] employees; public static final int MAXNUMEMP = 20; private int count = 0; public WorkerList() { employees = new Worker[MAXNUMEMP]; } //-------------------------- sortList ----------------------------------- public void sortList() { Arrays.sort(employees, 0, count); } //-------------------------- append ------------------------------------- public boolean append(Worker person) { if (count < MAXNUMEMP) { employees[count++] = person; // first assign, then increment return true; } return false; } //-------------------------- getSize ------------------------------------ public int getSize() { return count; } //-------------------------- display ------------------------------------ public void display() { for (int i = 0; i < count; i++) { System.out.println(employees[i]); } } }