UNB/ CS/ David Bremner/ teaching/ java/ TaxSort.java
public class TaxSort{

  public static void main(String[] args){

    String[] names={"bob","mary","joe","fred"};
    
    MergeList a=new MergeList();

    for (int i=0; i < names.length; i++){
      TaxRecord tr= new TaxRecord(names[i],i*1000);
      a.addLast(tr);
    }
    System.out.println("Original Order:");
    a.print();
    a.sort();
    System.out.println("\nSorted by name:");
    a.print();
    
  }
}



class TaxRecord
 implements Comparable{
  public String name;
  public int youOwe;

  public TaxRecord(String aName, int amt){
    name=aName;
    youOwe=amt;
  }

  public String toString(){
    return name+"\t"+youOwe;
  }

  public int compareTo(Object other){
    if (!(other instanceof TaxRecord))
      throw new ClassCastException("Type mismatch in compareTo");

    return name.compareTo(((TaxRecord)other).name);
  }
}

/*
cd /home/bremner/teach/1083/lecture/L10/
java -Djava.compiler=NONE TaxSort

Original Order:
bob     0
mary    1000
joe     2000
fred    3000

Sorted by name:
bob     0
fred    3000
joe     2000
mary    1000

Process TaxSort finished

*/