All pastes #265006 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-12-02 22:34 UTC
rendered paste body
package JavaLinkedListDemo;

import java.util.Comparator;    // for the implementing Comparable

public class Professor implements Comparable<Professor>
{
  private String strLastName;      // professor's last name 
  private String strFirstName;     // professor's first name
  private String strEmailAddress;  // professor's e-mail address
  private String strSpecialty;     // professor's specialty

  /** default constructor.
   *  This constructor calls the four-parameter constructor with four empty string values.
   */
  public Professor()
  {
    this("", "", "", "");  // call 4-parameter constructor with defaults
  }

  /** two-parameter constructor.
   *  This constructor calls the four-parameter constructor with empty string values for the
   *  third and fourth parameters (the professor's e-mail address and specialty).
   *  @param strLastName professor's last name
   *  @param strFirstName professor's first name
   */
  public Professor(
    String strLastName, String strFirstName)
  {
    // call 4-parameter constructor with defaults for third and fourth parameters
    this(strLastName, strFirstName, "", "");
  }

  /** four-parameter constructor.
   *  This is the standard constructor for a Professor object
   *  @param strLastName professor's last name
   *  @param strFirstName professor's first name
   *  @param strEmailAddress professor's e-mail address
   *  @param strSpecialty professor's specialty
   */
  public Professor(
    String strLastName, String strFirstName, String strEmailAddress, String strSpecialty)
  {
    this.strLastName = strLastName;     // save data passed in parameters
    this.strFirstName = strFirstName;
    this.strEmailAddress = strEmailAddress;
    this.strSpecialty = strSpecialty;
  }

  /** String representation of a Professor object 
   *  @return components of a Professor object within square brackets
   */
  public String toString()
  {
    return "[ " + strLastName + ", " + strFirstName + ", "
                + strEmailAddress + ", " + strSpecialty + " ]";
  }

  public int compareTo( Professor one )
  {
    // compare this lastname to param's lastname
    int lastCmp = strLastName.compareTo(one.strLastName);
    
    return( lastCmp != 0 ? lastCmp : 0 );//strFirstName.compareTo(one.strFirstName) );
  }

  //public int compare(LinkedList<Professor> p1, LinkedList<Professor> p2)
  //{
  //  return p1.strEmailAddress - p2.strEmailAddress;
  //}
}