package test3; import java.util.HashMap; import java.util.Map; /** * 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. Interval instances always ensure that the * following class invariant is true: * *

* minimum <= maximum * *

* Clients request Interval instances using the static method * Interval.getInstance. The class ensures that only one * Interval instance exists for each unique minimum-maximum pair. * Repeated calls to Interval.getInstance using the same minimum * and maximum values always return a reference to the same object; that is to * say: * *

* Interval.getInstance(1, 10) == Interval.getInstance(1, 10) is * always true. * * @author EECS1030Z_2014_15W * */ public class Interval { // YOU NEED TO ADD A FIELD TO COMPLETE THE MULTITON IMPLEMENTATION private int min; private int max; /** * Create an interval with the specified minimum and maximum values. * * @param min * the minimum value of the interval * @param max * the maximum value of the interval * @throws IllegalArgumentException * if min > max */ private Interval(int min, int max) { } /** * Get the interval having the desired minimum and maximum values. * * @param min * the minimum value of the interval * @param max * the maximum value of the interval * @return the interval (min, max) * @throws IllegalArgumentException * if min > max */ public static Interval getInstance(int min, int max) { } /** * Returns the minimum value of the interval * * @return the minimum value of the interval */ public int getMinimum() { } /** * Returns the maximum value of the interval * * @return the maximum value of the interval */ public int getMaximum() { } /** * Checks if value is inside this interval. A value is considered * inside this interval if both * *

* value >= minimum and value <= maximum * *

* are true. * * @param value * the value to check * @return true if value is inside this interval, * false otherwise */ public boolean contains(int value) { } /** * Return the width of this interval. The width of an interval is defined as * the maximum value of the interval minus the minimum value of the interval. * * @return the width of this interval */ public long width() { } /** * Return a new interval that contains the two given intervals. The width of * the new interval will be as small as possible. For example, if the two * intervals to be contained are: [-1, 1] and * [10, 12] then the new interval returned by this method is * [-1, 12]. * * * @param a * an interval to be contained by the new interval * @param b * the other interval to be contained by the new interval * @return a new interval that contains both intervals a and * b */ public static Interval containingInterval(Interval a, Interval b) { } /** * 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. For example, the string * *

* [-5, 8] * *

* represents the interval whose minimum value is -5 and whose * maximum value is 8 * * @return a string representation of the interval * @see java.lang.Object#toString() */ @Override public String toString() { return "(" + this.getMinimum() + ", " + this.getMaximum() + ")"; } }