Class Guess
java.lang.Object
|
+----Guess
- public class Guess
- extends Object
This class defines guesses of arbitrary length
as arrays of integers, along with some useful functions.
Zero represents a blank (unfilled) element.
This class was originally an extension of Vector
for greater flexibility, but the type-checking and protection
available by doing so seemed very poor.
-
equals(Guess)
- Shows if two guesses contain the same elements.
-
equals(Guess, int)
- Shows if two guesses have equal elements at a particular
position.
-
equals(Guess, int, int)
- Shows if two guesses have equal elements at particular
positions.
-
indexOf(int, int)
- Returns first position greater than the input
value at which a given value appears.
-
isFull()
- Show if all elements have been filled.
-
makeRandom(int, int)
- Fill guess with random integer values within 1 to an upper limit.
-
setValue(int, int)
- Set the value of an element.
-
toString(int)
- Used to print out one element instead of
the entire array.
toString
public String toString(int position)
- Used to print out one element instead of
the entire array.
setValue
public void setValue(int position,
int num)
- Set the value of an element.
- Parameters:
- position - element index
- num - new value
equals
public boolean equals(Guess correct)
- Shows if two guesses contain the same elements.
equals
public boolean equals(Guess attempt,
int position)
- Shows if two guesses have equal elements at a particular
position.
- Parameters:
- attempt - the guess to be compared
- position - position at which comparison is done
equals
public boolean equals(Guess attempt,
int position1,
int position2)
- Shows if two guesses have equal elements at particular
positions.
- Parameters:
- attempt - the guess to be compared
- position1 - position of calling object
at which comparison is done
- position2 - position of attempt
at which comparison is done
makeRandom
public void makeRandom(int range,
int maxDuplication)
- Fill guess with random integer values within 1 to an upper limit.
- Parameters:
- range - upper limit of generated value
- maxDuplication - maximum number of elements with the same
value permitted
isFull
public boolean isFull()
- Show if all elements have been filled.
indexOf
public int indexOf(int value,
int start)
- Returns first position greater than the input
value at which a given value appears. If it is
not found, -1 is returned.
- Parameters:
- value - value to be found
- start - index to start looking at