// This was a problem on an exam sometime.
public class PersonTest
{   public static void main(String[] args)
    {   Person[] per = new Person[4];
        per[0] = new Professor("a","Apple",1,5000.00);
        per[1] = new Student("b","Orange","CS");
        per[2] = new Staff("c","Plum",2,10.00);
        per[3] = new Student("f","Grape","CS");

        for(int i = 0; i < per.length; i++)
        {   System.out.println(per[i].name() + "s pay is $" + 
	        per[i].yearlyPay()); 
	}
        for (int i = 0 ; i < per.length ; i++)
        {   if (per[2].compareYearlyPay(per[i]) >= 0)
                System.out.println(per[2].name() + " >= " + per[i].name());
            else
                System.out.println(per[2].name() + " < " + per[i].name());
        }

    }
}

class Person
{   public Person(String pid, String n) { theId = pid; theName = n; }

    public void setName(String n) { theName = n; }

    public String id() { return theId; }

    public String name() { return theName; }

    public double yearlyPay() { return 0.0; }

    public int compareYearlyPay(Person q)
    {  double diff  = yearlyPay() - q.yearlyPay();
       int ret;
       if (diff < 0)      ret = -1;
       else if (diff > 0) ret =  1; 
       else               ret =  0;
       return ret;
    }

    private String theId;
    private String theName;
}

class Employee extends Person
{   public Employee(String pid, String n, int d) 
    { super(pid, n); theDept = d; }

    public int dept() { return theDept; }

    private int theDept;
}

class Professor extends Employee
{   public Professor(String pid, String n, int d, double s)
    {   super(pid, n, d); monthly_salary = s;  }

    public double monthlySalary() { return monthly_salary; }

    public double yearlyPay() { return monthly_salary * 9; }

    private double monthly_salary;
}

class Staff extends Employee
{   public Staff(String pid, String n, int d, double w)
    {   super(pid, n, d);  theHourlyWage = w;  }

    public double hourlyWage() { return theHourlyWage; }

    public double yearlyPay() { return theHourlyWage * 40 * 52; }

    private double theHourlyWage;
}

class Student extends Person
{   public Student(String pid, String n, String m) 
    { super(pid, n); theMajor = m; }

    public void setMajor(String m) { theMajor = m; }

    private String theMajor;
}

