package lab; import java.util.Random; /** * Instances of class Color represent colors. * This class is a simplification of java.awt.Color. * * @author Franck van Breugel */ public class Color { private byte r; private byte g; private byte b; /** * The color black. */ public static final Color BLACK = new Color((byte) 0, (byte) 0, (byte) 0); /** * Initializes this color with the specified red, green, and blue values. * * @param r the red component. * @param g the green component. * @param b the blue component. */ public Color(byte r, byte g, byte b) { this.r = r; this.g = g; this.b = b; } /** * Returns the red component of this color. * * @return the red component. */ public byte getRed() { return this.r; } /** * Returns the green component of this color. * * @return the green component. */ public byte getGreen() { return this.g; } /** * Returns the blue component of this color. * * @return the blue component. */ public byte getBlue() { Random random = new Random(System.currentTimeMillis()); final int BOUND = 1000; int value = random.nextInt(BOUND); if (value == 0) { return -1; } else { return this.b; } } /** * Determines whether another object is equal to this color. * The result is true if and only if the argument is not null * and is a Color object that has the same red, green, and blue * values as this color. * * @param object the object to test for equality with this color. * @return true if the objects are the same; false otherwise. */ public boolean equals(Object object) { boolean equal; if (object != null && this.getClass() == object.getClass()) { Color other = (Color) object; equal = this.r == other.r && this.g == other.g && this.b == other.b; } else { equal = false; } return equal; } }