Source of ListClient.java


  1: /** 
  2:    A driver that uses a list to track the runners in a race
  3:    as they cross the finish line.
  4: 
  5:    @author Frank M. Carrano
  6:    @author Timothy M. Henry
  7:    @version 4.0
  8: */
  9: public class ListClient 
 10: {
 11:         public static void main(String[] args) 
 12:         {
 13:                 testList();
 14:         }  // end main
 15: 
 16:         public static void testList() 
 17:         {
 18:       ListInterface<String> runnerList = new AList<>();
 19:   //  runnerList has only methods in ListInterface
 20: 
 21:       runnerList.add("16"); // Winner
 22:       runnerList.add(" 4"); // Second place
 23:       runnerList.add("33"); // Third place
 24:       runnerList.add("27"); // Fourth place
 25:       displayList(runnerList);
 26:    } // end testList
 27:    
 28:    public static void displayList(ListInterface<String> list)
 29:    {
 30:       int numberOfEntries = list.getLength();
 31:       System.out.println("The list contains " + numberOfEntries +
 32:                          " entries, as follows:");
 33:       for (int position = 1; position <= numberOfEntries; position++)
 34:          System.out.println(list.getEntry(position) +
 35:                             " is entry " + position);
 36:       System.out.println();
 37:    } // end displayList
 38: } // end ListClient
 39: 
 40: /*
 41: The list contains 4 entries, as follows:
 42: 16 is entry 1
 43:  4 is entry 2
 44: 33 is entry 3
 45: 27 is entry 4
 46: */