package eecs1022.finala; /** * A class that represents an interval of values on the integer number line. An * interval has two properties: a minimum value and a maximum value. * * @author Franck van Breugel */ public class Interval { private int min; private int max; /** * Initializes this interval with the given minimum and maximum values. * * @param min the minimum value of this interval. * @param max the maximum value of the interval. */ public Interval(int min, int max) { this.min = min; this.max = max; } /** * Checks if the given value is inside this interval. * * @param value the value to check * @return true if value ≥ minimum of this interval and * value ≤ maximum of this interval, false otherwise. */ public boolean contains(int value) { return this.min <= value && value <= this.max; } /** * Returns a copy of this interval, that is, a new interval * with the same minimium and maximum. * * @return a copy of this interval. */ public Interval copy() { return new Interval(this.min, this.max); } /** * Returns the string representation of this interval. The string contains the * minimum and maximum values separated by a comma and space all inside of a * pair of square brackets. * * @return a string representation of this interval. */ public String toString() { return "[" + this.min + ", " + this.max + "]"; } }