public class Range
extends java.lang.Object
minimum <= value <= maximum
The mutator methods of the class are responsible for ensuring that the above class invariant is always true. For example, if the minimum value of the range is changed so that it is greater than the current value, then the current value is also adjusted to maintain the class invariant. If the minimum value is changed so that it is greater than the maximum value, then both the maximum value and current value are also changed to maintain the class invariant.
Constructor and Description |
---|
Range()
Create a range with minimum value 0, maximum value 100, and initial value
50.
|
Range(int min,
int max)
Create a range with the specified minimum and maximum values.
|
Range(int min,
int max,
int init)
Create a range with the specified minimum, maximum, and initial values.
|
Modifier and Type | Method and Description |
---|---|
int |
getMaximum()
Returns the maximum value of the range
|
int |
getMinimum()
Returns the minimum value of the range
|
int |
getValue()
Return the current value of the range.
|
void |
setMaximum(int newMaximum)
Sets the maximum value of the range to
newMaximum . |
void |
setMinimum(int newMinimum)
Sets the minimum value of the range to
newMinimum . |
void |
setValue(int newValue)
Set the current value of the range to
newValue if
newValue satisfies the constraints of the range. |
public Range()
public Range(int min, int max)
max - min
is odd).min
- the minimum value of the rangemax
- the maximum value of the rangejava.lang.IllegalArgumentException
- if min > max
public Range(int min, int max, int init)
min
- the minimum value of the rangemax
- the maximum value of the rangeinit
- the initial value of the rangejava.lang.IllegalArgumentException
- if the constraint min <= init <= max
is not
satisfiedpublic int getMinimum()
public void setMinimum(int newMinimum)
newMinimum
. The other
properties of the range may be changed to ensure that:
minimum <= value <= maximum
newMinimum
- the new minimum of the rangepublic int getMaximum()
public void setMaximum(int newMaximum)
newMaximum
. The other
properties of the range may be changed to ensure that:
minimum <= value <= maximum
newMaximum
- the new maximum of the rangepublic int getValue()
public void setValue(int newValue)
newValue
if
newValue
satisfies the constraints of the range. Those
constraints are:
minimum <= value <= maximum
Otherwise, if newValue < minimum
then the value is set to the
minimum value of the range, and if newValue > maximum
then the
value is set to the maximum value of the range.
value
- the new value of the range