Source of RoadRace.java


  1: /** 
  2:    A driver that uses a list to track the runners in a race
  3:    as they cross the finish line.
  4:    @author Frank M. Carrano
  5:    @author Timothy M. Henry
  6:    @version 5.0
  7: */
  8: public class RoadRace
  9: {
 10:         public static void main(String[] args) 
 11:         {
 12:                 recordWinners();
 13:         }  // end main

 15:         public static void recordWinners()
 16:         {
 17:       ListInterface<String> runnerList = new AList<>();
 18:   //  runnerList has only methods in ListInterface

 20:       runnerList.add("16"); // Winner
 21:       runnerList.add(" 4"); // Second place
 22:       runnerList.add("33"); // Third place
 23:       runnerList.add("27"); // Fourth place
 24:       displayList(runnerList);
 25:    } // end recordWinners
 26:    
 27:    public static void displayList(ListInterface<String> list)
 28:    {
 29:       int numberOfEntries = list.getLength();
 30:       System.out.println("The list contains " + numberOfEntries +
 31:                          " entries, as follows:");
 32:       for (int position = 1; position <= numberOfEntries; position++)
 33:          System.out.println(list.getEntry(position) +
 34:                             " is entry " + position);
 35:       System.out.println();
 36:    } // end displayList
 37: } // end RoadRace

 39: /*
 40: The list contains 4 entries, as follows:
 41: 16 is entry 1
 42:  4 is entry 2
 43: 33 is entry 3
 44: 27 is entry 4
 45: */