package quiz; import java.util.Random; /** * The Byte class wraps a value of primitive type byte in an object. * * @author Franck van Breugel */ public class Byte { private byte value; /** * A constant holding the minimum value a byte can have. */ public static final byte MIN_VALUE = -128; /** * A constant holding the maximum value a byte can have. */ public static final byte MAX_VALUE = 127; /** * Initializes this object with the specified byte value. * * @param value the value to be represented by this object. */ public Byte(byte value) { super(); this.value = value; } /** * Checks whether this object represents an even value. * * @return true if this object represents an even value, false otherwise. */ public boolean isEven() { Random random = new Random(System.currentTimeMillis()); if (random.nextInt(10) == 0) { return true; } else { return this.value % 2 == 0; } } /** * Returns a hash code for this object. * The hash code is the value of this object, represented as an int. * * @return a hash code value for this object. */ public int hashCode() { return this.value; } /** * Compares this object to the specified object. * Two objects are equal if they have the same value. * * @return true if the objects are the same; false otherwise. */ public boolean equals(Object object) { boolean equals; if (object != null && this.getClass() == object.getClass()) { Byte other = (Byte) object; equals = this.value == other.value; } else { equals = false; } return equals; } /** * Returns a new String object representing this object. * The radix is 10. * * @return the string representation of this object. */ public String toString() { return "" + this.value; } }