Hello. Nearly finish this project, but can't sort the last code. I have faculty, staff, & partime employees, and they have ID, and what I want to do is sort by ascending order them based on their #ID. Everything else works before that. Here is my two codes, the Tester, and my Partime class code.

import java.util.Calendar;
import java.util.Scanner;

public class TestEmployee implements EmployeeInfo{


    public static void main(String[] args) throws CloneNotSupportedException {


    /**
     * Part A: output all employee from Staff, Faculty, and partime.
     */

        double sum=0,total=0;

        DataItem[] emp = new Employee[9];
        Calendar staffBirthDate = Calendar.getInstance();
        Calendar facultyBirthDate = Calendar.getInstance();
        Calendar partimeBirthDate = Calendar.getInstance();
        staffBirthDate.set(1959, 2, 23);// Scott Chan
        emp[0] = new Staff("Chan, Scott", 123, 'M', staffBirthDate, 35.00);

         staffBirthDate = Calendar.getInstance();

        staffBirthDate.set(1964, 7, 12);// Brian Salinas
        emp[1] = new Staff("Salinas, Brian", 456, 'F', staffBirthDate, 30.00);

         staffBirthDate = Calendar.getInstance();

        staffBirthDate.set(1970, 6, 2);// Allen Weir
        emp[2] = new Staff("Weir, Allen", 789, 'M', staffBirthDate, 22.00);

        facultyBirthDate = Calendar.getInstance();

        facultyBirthDate.set(1962, 4, 27);
        emp[3] = new Faculty("Im, Lee", 243, 'F', facultyBirthDate, "Full", "PH.D", "Engineering", "3");

        facultyBirthDate = Calendar.getInstance();

        facultyBirthDate.set(1975, 3, 14);// 
        emp[4] = new Faculty("Bui, Thung", 791, 'F', facultyBirthDate, "Associate", "PH.D", "English", "1");

        facultyBirthDate = Calendar.getInstance();


        facultyBirthDate.set(1980, 5, 22);//
        emp[5] = new Faculty("Monreno, Maria", 623, 'F', facultyBirthDate, "Assistant", "MS", "Physical Education", "0");
         System.out.println("\nTotal montly Salary for all employees");

         partimeBirthDate = Calendar.getInstance();

         partimeBirthDate.set(1977, 8, 10);
        emp[6] = new Partime("Lee, Chesong", 455, 'F', partimeBirthDate, 20, 35.00);

         partimeBirthDate = Calendar.getInstance();


            partimeBirthDate.set(1987, 9, 15);
        emp[7] = new Partime("Garcia, Frank", 678, 'M', partimeBirthDate, 25, 30.00);

         partimeBirthDate = Calendar.getInstance();

            partimeBirthDate.set(1980, 8, 22);//
        emp[8] = new Partime("Alquilo, Roscoe", 945, 'M', partimeBirthDate, 30, 20.00);

        for(int i = 0; i<emp.length;i++)
        {
            if(emp[i] instanceof Staff)
            {
                System.out.println("\n"+emp[i]);
            }//end of if statement
            if(emp[i] instanceof Faculty)
            {
                System.out.println("\n"+emp[i]);
            }//end of if statement

        }// end of for loop

          System.out.println("\nTotal montly Salary for all employees\n");
            for(int i = 0; i<emp.length; i++)
            { 
                sum = ((Employee) emp[i]).monthlyEarning()+sum;
            }
            System.out.println("$"+sum);
            //c
            System.out.println("\nTotal monthly salary for all faculuty");
            for(int i = 0; i<emp.length;i++)
            {
                if(emp[i] instanceof Faculty)
                {
                    total = ((Employee) emp[i]).monthlyEarning()+total;
                }
            }
            System.out.println("$"+total);
          //Part D Duplicate a faculty object. test the duplication
            Faculty f1 = (Faculty)emp[4];
            Faculty f2 = (Faculty)f1.clone();
            Education dupl = new Education("PH.D",
                    "Doctor", "4");
            f2.setEducation(dupl);
            System.out.println("\nD Duplicate a Faculty Object"
                    +"\n"+f2.toString());

            //Part E Verify two staff objects are the same

            System.out.println("\nE.Verify two staff objects ");
            Staff s1 = (Staff)emp[6];
            Staff s2 = (Staff)s1.clone();
             staffBirthDate = Calendar.getInstance();

            Staff s3 = new Staff("Danger, Norman", 456, 'M', staffBirthDate, 25.00);
            if(s1.getBirthdate()==s2.getBirthdate())
            {
                System.out.print("\nThe two staff objects " +
                        " birthdays"+ " are the same "
                        +"therefore "+true+"\n");
            }
            if(s3.getBirthdate()==s1.getBirthdate())
            {
                System.out.print(true);
            }

            //F Sort employees by ascending employee ID
            System.out.println("\nSort employees by ID");

            for(int i=0;i<emp.length;i++)
            {
                SortArrayClass.sort(emp);

                System.out.println("\n"+emp[i]);
            }
    }
}

At the very end of the code is where it really is not sorting. My Partime class as one of the 3 classes I want to implement to sort the employee's id

import java.util.Calendar;

public class Partime <T> extends Staff implements EmployeeInfo, Comparable {

    private int hourlyWeek;
    private double hourlyRate;

    /**
     * Default constructor
     */
    public Partime() {
        super();
        hourlyWeek = 0;
        hourlyRate = 0.00;
    }

    public Partime(String name, int idNumber, char gender, Calendar birthdate,
            int hourlyWeek, double hourlyRate) {
        super(name, idNumber, gender, birthdate, hourlyWeek);
        this.hourlyWeek = hourlyWeek;
        this.hourlyRate = hourlyRate;
    }

    /**
     * Calculates the monthly earning based on the partime's hourly rate.
     * 
     * @return monthlyEarning the monthly earning
     */
    public double monthlyEarning() {
        double monthlySalary = 4 * (hourlyRate * hourlyWeek);
        return monthlySalary;
    }

    /**
     * Gets the Partime's hourly rate.
     * 
     * @return the hourlyRate
     */
    public int getHourlyWeek() {
        return hourlyWeek;
    }

    /**
     * Sets the Partime's hourly rate.
     * 
     * @param hourlyRate
     *            the hourlyRate to set
     */
    public void setHourlyWeek(int hourlyWeek) {
        this.hourlyWeek = hourlyWeek;
    }

    public double getHourlyRate(){
    return hourlyRate;
}
    public void setHourlyRate(double hourlyRate){
        this.hourlyRate = hourlyRate;
    }


    /**
     * Compares ID numbers of the Partime object.
     * @return true if they are equal, false otherwise.
     */
    public boolean equals(Object o) {
      if(o instanceof Partime)
        return getIdNumber() == ((Partime) o).getIdNumber(); 
      else
        return false; 
    }


    /**
     * Displays the Staff's Employee ID number, name, birth date, and monthly
     * salary. All Staff employees are full time, which is also displayed.
     */
    public String toString() {
        return "\n\nID Employee Number: " + getIdNumber() + 
            "\nEmployee Name: " + getEmployeeName() + 
            "\nSex: " + getGender() +
            "\nBirth date: " + getBirthdate().get(Calendar.YEAR) + "/" + getBirthdate().get(Calendar.MONTH) + "/" + getBirthdate().get(Calendar.DATE) +
            "\nHours works per month: " + getHourlyWeek() + 
            "\nMonthly Earnings: $" + monthlyEarning(); // getHourlyRate();



    }

    /**
     * Copy constructor
     * @returns a Partime copy
     */
    public Partime getCopy() {
        return new Partime(this.getEmployeeName(), this.getIdNumber(), 
                this.getGender(), this.getBirthdate(), this.getHourlyWeek(), this.getHourlyRate());
    }


    /**
     * Compares two Employee's ID numbers.
     * 
     * @param o
     *            DataItem to compare
     * @return 1 if the Employee's ID number is less than DataItem's ID number, -1
     *         if greater, and 0 if they equal.
     */
    public int compareTo(Object o) {

        if (o instanceof Partime) {
            int idNumber1 = ((Partime) o).getIdNumber();
            int idNumber2 = this.getIdNumber();
            if (idNumber1 < idNumber2) {
                return 1;
            } else if (idNumber1 > idNumber2) {
                return -1;
            } else {
                return 0;
            }

            //return (Integer) this.getIdNumber() - (Integer) ((Staff)o).getIdNumber();
        }
        else
            return (Integer) this.getIdNumber() - (Integer)o;

    }
}

Any help is appreciated.

Edited 3 Years Ago by kay19: change coding a bit

Update: I think I have to rework on my Array class & SortArray Class. I don't know how to implement the insertion sort. Sort Array Class

public class SortArrayClass extends ArrayClass {


    public SortArrayClass() {
        super();
    }

    public SortArrayClass(int theMaxSize) {
        super(theMaxSize);
    }

public void insertionSort(int length) {
            for (int i = 1; i < length; i++) {

            }
        }

Guess I have to rework on insertionsort coding.

I'm not sure

Update #2. I figured to use Arrays.sort. I just had to redo my other classes. It sorts, but if I want to descending sort, I am guessing I have to use Comperator class for that to happen. Anywho, i'll mark this question as solved, but if you guys want to chime in about about the Comperator class, feel free.

This question has already been answered. Start a new discussion instead.