package test3;
/**
* A class that represents a range of values on the real number line. A range
* has two properties: a minimum
value and a maximum
* value. Range objects always ensure that the following class invariant is
* true:
*
*
* minimum <= maximum
*
*
* The constructors of the class are responsible for ensuring that the above
* class invariant is always true.
*
*
*/
public class Range {
private static double DEFAULT_MIN = 0;
private static double DEFAULT_MAX = 100;
private double min;
private double max;
/**
* Create a range with minimum value 0 and a maximum value 100.
*/
public Range() {
}
/**
* Create a range with the specified minimum and maximum values.
*
* @param min
* the minimum value of the range
* @param max
* the maximum value of the range
* @throws IllegalArgumentException
* if min > max
*/
public Range(double min, double max) {
}
/**
* Returns the minimum value of the range
*
* @return the minimum value of the range
*/
public double getMinimum() {
}
/**
* Returns the maximum value of the range
*
* @return the maximum value of the range
*/
public double getMaximum() {
}
/**
* Checks if value
is inside this range. A value is considered
* inside this range if both
*
*
* value >= minimum
and value <= maximum
*
*
* are true.
*
* @param value
* the value to check
* @return true
if value
is inside this range,
* false
otherwise
*/
public boolean contains(double value) {
}
/**
* Checks if this range overlaps with another range. Two ranges overlap if at
* least one double
value is contained by both ranges. For
* example, the two ranges
*
*
* [0.1, 0.8]
and [0.6, 2.5]
overlap because all
* values between 0.6
and 0.8
are contained by both
* ranges.
*
*
* The two ranges * *
* [-0.25, 0.33]
and [0.33, 1.0]
overlap because
* both ranges contain the value 0.33
*
*
* @param other
* the other range to check
* @return true
if this range overlaps with other
,
* and false
otherwise.
*/
public boolean overlaps(Range other) {
}
/**
* Return a new range that is centered at value
and whose total
* width is width
. For example:
*
*
* Range.centeredAt(10.0, 5.0)
*
*
* would return the range [7.5, 12.5]
.
*
*
* @param value
* the center of the desired range
* @param width
* the total width of the desired range
* @pre. width >= 0
* @return a new Range
centered at value
and whose
* total width is width
*/
public static Range centeredAt(double value, double width) {
}
/**
* Returns the string representation of a range. 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
*
*
* [-3.14, 3.14]
*
*
* represents the range whose minimum value is -3.14
and whose
* maximum value is 3.14
*
* @return a string representation of the range
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
}
/**
* Returns a hash code for this range.
*
* @return a hash code for this range
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(max);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(min);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
/**
* Compares this Range
to the specified Object
. The
* result is true if and only if the argument is a Range
object
* having the same minimum and maximum value as this object.
*
* @param obj
* the object to compare with
* @return true
if this object is equal to obj
;
* false
otherwise
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Range other = (Range) obj;
if (Double.doubleToLongBits(max) != Double.doubleToLongBits(other.max)) {
return false;
}
if (Double.doubleToLongBits(min) != Double.doubleToLongBits(other.min)) {
return false;
}
return true;
}
}