Lecture Summary for 211 on 3/26/04 -- Barat Section

 

Review Questions

  1. Explain the difference between an accessor method and a mutator method.

  2. Match the method types in Column 1 with the items in Column 2.
    Column 1 Column 2
    Mutator One return value
    Accessor No return value
      One parameter
      No parameter

  3. Which type of method does not specify a return type in its header.

  4. What is wrong with this constructor definition?
    public MyClass()
    {
        MyClass x = MyClass();
    }

  5. What is garbage? How do you create it and get rid of it?

  6. What gets printed?
    Kid x = new Kid("Mary", 'F', 12);
    Kid y = new Kid("Tom", 'M', 10);
    Kid temp;

    temp = x;
    x = y;
    y = temp;

    System.out.println(x);
    System.out.println(y);

  7. Write lines of Java code that print "yes" if x is female and "no" otherwise. Assume the class definition Kids2. Do not hardcode your answer for this particular x.

  8. Write lines of Java code that print the length of the name for y. Do not hardcode your answer for this particular y.

  9. Write an equals method for the Point class. Two Point objects p and q are equal if p.x == q.x and q.x == q.y.

  10. Write a main method to test your equals method in the previous problem.

 

The StringTokenizer

 

Arrays in Java

 

The Sorting Examples

The Art of Debugging

 

The Steps of Inductive Debugging

  1. Collect data about the bug. When does the program perform correctly and when does it perform incorrectly.

  2. Organize the data. Answer these questions: what, when, and where. When does an error occur and when does it not occur?

  3. Formulate a hypotheses about what is causing the bug.

  4. Prove the hypotheses.

  5. Fix the bug and continue to look for more bugs. Resist the urge to skip directly from Step 3 to Step 5.

 

The BlueJ Debugger

 

Debugging Examples