Source of EnumTest.java


  1: // Fig. 8.11: EnumTest.java
  2: // Testing enum type Book.
  3: import java.util.EnumSet;
  4: 
  5: public class EnumTest 
  6: {
  7:    public static void main( String args[] ) 
  8:    {
  9:       System.out.println( "All books:\n" );
 10: 
 11:       // print all books in enum Book                          
 12:       for ( Book book : Book.values() )                        
 13:          System.out.printf( "%-10s%-45s%s\n", book,
 14:              book.getTitle(), book.getCopyrightYear() );
 15: 
 16:       System.out.println( "\nDisplay a range of enum constants:\n" );
 17:     
 18:       // print first four books                                 
 19:       for ( Book book : EnumSet.range( Book.JHTP6, Book.CPPHTP4 ) )
 20:          System.out.printf( "%-10s%-45s%s\n", book,
 21:              book.getTitle(), book.getCopyrightYear() );
 22:    } // end main
 23: } // end class EnumTest
 24: 
 25: 
 26: /**************************************************************************
 27:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 28:  * Pearson Education, Inc. All Rights Reserved.                           *
 29:  *                                                                        *
 30:  * DISCLAIMER: The authors and publisher of this book have used their     *
 31:  * best efforts in preparing the book. These efforts include the          *
 32:  * development, research, and testing of the theories and programs        *
 33:  * to determine their effectiveness. The authors and publisher make       *
 34:  * no warranty of any kind, expressed or implied, with regard to these    *
 35:  * programs or to the documentation contained in these books. The authors *
 36:  * and publisher shall not be liable in any event for incidental or       *
 37:  * consequential damages in connection with, or arising out of, the       *
 38:  * furnishing, performance, or use of these programs.                     *
 39:  *************************************************************************/