{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Computer Science 61B - Spring 1999 - Clancy - Midterm 3

# Computer Science 61B - Spring 1999 - Clancy - Midterm 3 -...

This preview shows pages 1–3. Sign up to view the full content.

CS 61B, MT3, Spring 1999 CS 61B, Spring 1999 MT3 Professor M. Clancy Problem #1 One approach to producing debugging output is to use inheritance to create objects that print any changes to themselves. For instance, instead of a Interval in homework assignment 4, one might have a TracedInterval that inherits from Interval, in which: (1) each constructor is overridden so that after initializing, it prints the Interval object; (2) the extendThrough method is overridden so that after updating, it prints the new value of the Interval object. Suppose for the purposes of this problem that the Interval class from homework assignment 4 is defined as follows: public class Interval { private double myLeft; private double myRight; // Constructor. public Interval (double left, double right) . . . // Return this interval's left endpoint. public double left ( ) . . . // Return this interval's right endpoint. public double right ( ) . . . // Return a hash value for this interval. public int hashCode ( ) . . . // Return true when this interval represents the same interval // as the argument; return false otherwise. public boolean equals (Interval intvl) . . . // Return true exactly when this interval contains x; // return false otherwise. public boolean contains (double x) . . . // Return true when this interval overlaps the argument, // i.e. contains integers in common with it; file:///C|/Documents%20and%20Settings/Jason%20Raft. ..20Spring%201999%20-%20Clancy%20-%20Midterm%203.htm (1 of 6)1/27/2007 6:33:03 PM

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 61B, MT3, Spring 1999 // returns false otherwise. public boolean overlaps (Interval intvl) . . . // Extend this interval to include all the points in the argument. // Precondition: overlaps (intvl). public void extendThrough (Interval intvl) . . . } In the space below, define the TraceInterval class described above. The main program: public static void main (String [ ] args) { TracedInterval intvl = new TracedInterval(1.0, 3.0); intvl.extendThrough(2.5, 6.0); } should produce something like the following as output: new interval is [1.0, 3.0]
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

Computer Science 61B - Spring 1999 - Clancy - Midterm 3 -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online