public class Range extends Object
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.
Constructor and Description |
---|
Range()
Create a range with minimum value 0 and a maximum value 100.
|
Range(double min,
double max)
Create a range with the specified minimum and maximum values.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares this
Range to the specified Object . |
double |
getMaximum()
Returns the maximum value of the range
|
double |
getMinimum()
Returns the minimum value of the range
|
int |
hashCode()
Returns a hash code for this range.
|
String |
toString()
Returns the string representation of a range.
|
public Range()
public Range(double min, double max)
min
- the minimum value of the rangemax
- the maximum value of the rangeIllegalArgumentException
- if min is greater than maxpublic double getMinimum()
public double getMaximum()
public String toString()
[-3.14, 3.14]
represents the range whose minimum value is -3.14
and whose
maximum value is 3.14
toString
in class Object
Object.toString()
public int hashCode()
hashCode
in class Object
Object.hashCode()
public boolean equals(Object obj)
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.equals
in class Object
obj
- the object to compare withtrue
if this object is equal to obj
;
false
otherwiseObject.equals(java.lang.Object)