There is only one copy of it public class chapter

This preview shows page 7 - 11 out of 12 pages.

There is only ONE copy of it. public class Chapter { private String title; // title of chapter private static int numberChaps= 0; // no. of folders created } Reference static variable using Chapter.numberChaps a0 Chapter title “peace” a1 Chapter title “truth” numberChaps 2 File drawer for class Chapter Use a static variable when you want to maintain information about all (or some) folders.
Image of page 7

Subscribe to view the full document.

8 Make a method static when it does not refer to any of the fields or methods of the folder. public class Chapter { private int number; // Number of chapter private static int numberOfChapters= 0; /** = “This chapter has a lower chapter number than Chapter c”. Precondition: c is not null. */ public boolean isLowerThan(Chapter c) { return number < c.number; } } /** = “b’s chapter number is lower than c’s chapter number”. Precondition: b and c are not null. */ public static boolean isLower(Chapter b, Chapter c) { return b.number < c.number; }
Image of page 8
9 Testing --using Junit. Pages 385-388 (through Sec. 14.1.1). Bug : Error in a program. Testing : Process of analyzing, running program, looking for bugs. Test case : A set of input values, together with the expected output. Debugging : Process of finding a bug and removing it. Get in the habit of writing test cases for a method from the specification of the method even before you write the method. To create a framework for testing in DrJava, select menu File item new Junit test case… . At the prompt, put in the class name ChapterTester . This creates a new class with that name. Immediately save it —in the same directory as class Chapter. The class imports junit.framework.TestCase , which provides some methods for testing.
Image of page 9

Subscribe to view the full document.

10 1. c1= new Chapter(“one”, 1, null ); Title should be: “one”; chap. no.: 1; previous: null . 2. c2= new Chapter(“two”, 2, c1); Title should be: “two”; chap. no.: 2; previous: c1.
Image of page 10
Image of page 11
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern