// File: GenericListTest.java // // Author: Rahul Simha // Created: Sept 21, 1998 // // Testing the GenericList. // An object to use in the list: class Person { String name; String ssn; // Constructor. public Person (String nameInit, String ssnInit) { name = nameInit; ssn = ssnInit; } // Override toString() public String toString () { return "Person: name=" + name + ", ssn=" + ssn; } } // Test class. public class GenericListTest { public static void main (String[] argv) { // Create a new list object. GenericList L = new GenericList (); // Let's 10 random numbers between 1 and 100 for (int i=1; i <= 10; i++) { int k = (int) UniformRandom.uniform (1L,100L); Integer K = new Integer (k); // Integer object. L.addData (K); } // Print contents. L.printList(); // Enumerate items. L.startEnumeration(); while (L.hasMoreElements()) { Integer K = (Integer) L.getNextElement(); // Integer has overridden toString() System.out.println (K); } } }