ANSWERS TO JAVA EXERCISES


 1. Java classes provide language support for us to associate
    functions (methods) with our data; C structures do not.

 2. A java class for intervals on the line, with a method that computes
    the length of intervals.

 3. new Interval(1.0, 2.5).length()

    In this usage, we create the object only to get at the length method.
    If we have other uses for the interval, we might declare and name
    a variable, e.g.

          Interval t = new Interval(1.0, 2.5);
          
    Then we could use "t.length()" in expressions.

 4.
          class Rect {
             private Interval x, y;

             Rect(Interval xval, Interval yval) {
                x = xval; y = yval;
             }

             double area() {
                return x.length() * y.length();
             }
          }

 5. new Rect(new Interval(1.0, 2.5), new Interval(2.0, 4.0)).area()

 6. To hide it from clients.  Otherwise, we would not be free to 
    change the implementation because clients might use it.

 7. To define it as a part of the class that is for use by clients.

 8.
        list.next = list.next.next;

 9.
        Node t = new Node(5);
        t.next = list.next.next; list.next.next = t;