import SimpleOutput; /** * Test our sample book class. Does not yet test all issues * (such as zero-parameter constructors). * * @author Samuel A. Rebelsky * @version 1.0 of September 1999 */ public class BookTester { public static void main(String[] args) throws Exception { SimpleOutput out = new SimpleOutput(); Book eij = new Book("Sam Rebelsky", "Experiments in Java"); // Print the basic information. out.println("* Test: Print basic information"); out.print(eij.toString()); // Set two chapters. out.println("\n*Test: Set two chapters"); eij.addChapter("J1: An Introduction to Java"); eij.addChapter("J2: Objects and Classes"); out.print(eij.toString()); // Get an valid chapter. out.println("\n*Test: Get valid chapter"); out.println("Chapter 2: " + eij.getChapter(2)); // Get an invalid chapter. out.println("\n*Test: Get invalid chapter"); try { out.println("Chapter 4: " + eij.getChapter(4)); } catch (Exception e) { out.println("As expected, that failed."); } // Add too many chapters out.println(); for (int i = eij.getNumChapters(); i < 25; ++i) { try { out.print("*Test: Adding chapter " + i + "..."); eij.addChapter("Untitled"); out.println("okay"); } catch (Exception e) { out.println("failed"); } // caught "too many chapters" exception } // add a lot of chapters // And see what we have out.println("\n*Final version:"); out.println(eij.toString()); } // main(String[]) } // class BookTester