# Homework 20: Exceptional Comparison

Due: Wednesday, 29 September 2004

Suppose we are creating a class, Assistant, that performs many common activities. One such activity is, given two objects, a and b, to determine which of the two is smaller. Suppose we call that the corresponding method `min`.

```/**
* Find the smaller of two comparable objects.
*/
public Comparable min(Comparable a, Comparable b)
```

Through analysis, we determine that

• `min` should return `a` if `a` thinks it is smaller than `b` and `b` thinks it is larger than `a`.
• `min` should return `b` if `b` thinks it is smaller than `a` and `a` thinks it is larger than `b`.
• If both `a` and `b` report that they are equal, return either.
• If either `a` or `b` throws an exception upon being asked to compare the other value, `min` should throw an `IncomparableException` (which you must write).
• If you get inconsistent orders from `a` and `b`, `min` should throw an `InconsistentException` (which you must write).

Implement and test `min`.

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Wed Dec 8 10:36:54 2004.
The source to the document was last modified on Tue Sep 28 10:58:04 2004.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2004F/Homework/20.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu