At right, write a definition of a new type, called IntRange,
representing a range of integers. This class should support the
following instance methods.
The following example method, which uses the IntRange class you
define, illustrates how the class should work.
public static void run() {
IntRange range = new IntRange(2, 4);
IO.println(range.getSize()); // this prints ``3''
IO.println(range.contains(1)); // this prints ``false''
IO.println(range.contains(3)); // this prints ``true''
IO.println(range.contains(4)); // this prints ``true''
IO.println(range.contains(5)); // this prints ``false''
}
public class IntRange {
}
public class IntRange { private int first; private int last; public IntRange(int start, int end) { first = start; last = end; } public int getSize() { return last - first + 1; } public boolean contains(int i) { return start <= i && i <= last; } }