import java.util.*; import java.io.*; /************************************************** * Tests the implementation of the comparableRecord class. * @author: Sriram Pemmaraju */ public class comparableRecordTester{ public static void main(String args[]) { // Defining and allocating space for an array of comparableRecord objects comparableRecord[] recList; recList = new comparableRecord[5]; // Initializing the slots of the array recList[0] = new comparableRecord("500", "Alice", 124.24); recList[1] = new comparableRecord("200", "John", 14.40); recList[2] = new comparableRecord("100", "Bob", 654.2); recList[3] = new comparableRecord("300", "Tudor", 11.00); recList[4] = new comparableRecord("400", "Tray", 14.25); // Sorting the array Arrays.sort(recList); // Printing it out for(int i = 0; i < 5; i++) System.out.println(recList[i].ssn + " " + recList[i].name); // Defining an empty ArrayList object ArrayList anotherRecList = new ArrayList(); // Adding a bunch of comparableRecord objects to the ArrayList objects anotherRecList.add(new comparableRecord("500", "Alice", 124.24)); anotherRecList.add(new comparableRecord("200", "John", 14.40)); anotherRecList.add(new comparableRecord("100", "Bob", 654.2)); anotherRecList.add(new comparableRecord("300", "Tudor", 11.00)); anotherRecList.add(new comparableRecord("400", "Tray", 14.25)); // Sorting the ArrayList object Collections.sort(anotherRecList); // Printing out the contents of the ArrayList in order using the get method int size = anotherRecList.size(); for(int i = 0; i < size; i++) { comparableRecord temp = anotherRecList.get(i); System.out.println(temp.ssn + " " + temp.name); } // Printing out the contents of the ArrayList in order using an Iterator Iterator itr = anotherRecList.iterator(); while(itr.hasNext()){ comparableRecord temp = itr.next(); System.out.println(temp.ssn + " " + temp.name); } } }