public class Color139
{
	public static final Color139 BLACK = new Color139(0,0,0);
	public static final Color139 RED = new Color139(255,0,0);
	public static final Color139 GREEN = new Color139(0,255,0);
	public static final Color139 YELLOW = new Color139(255,255,0);
	public static final Color139 BLUE = new Color139(0,0,255);
	public static final Color139 MAGENTA = new Color139(255,0,255);
	public static final Color139 CYAN = new Color139(0,255,255);
	public static final Color139 WHITE = new Color139(255,255,255);

	private int red;
	private int green;
	private int blue;

	/*************************************************************
	 * This constructor creates a Color139 object with the specified
	 * RGB values. If a value less than 0 is specified, that color's
	 * value is set to 0. If a value greater than 255 is specified,
	 * that color's value is set to 255.
	 * @param redVal   The color's red component as a value 0-255
	 * @param greenVal The color's green component as a value 0-255
	 * @param blueVal  The color's blue component as a value 0-255
	 *************************************************************/
	public Color139(int redVal, int greenVal, int blueVal)
	{
		this.red = redVal;
		this.green = greenVal;
		this.blue = blueVal;
		if (this.red < 0)
			this.red = 0;
		else if (this.red > 255)
			this.red = 255;
		if (this.green < 0)
			this.green = 0;
		else if (this.green > 255)
			this.green = 255;
		if (this.blue < 0)
			this.blue = 0;
		else if (this.blue > 255)
			this.blue = 255;
	}

	/*************************************************************
	 * This method returns a string representation of the color
	 * in the form "#RRGGBB" where RR, GG, and BB are the red, green
	 * and blue values expressed as hexidecimal digits.
	 * @return The string representation of the color
	 *************************************************************/
	public String toString()
	{
		String redStr;
		String greenStr;
		String blueStr;

		redStr = Integer.toHexString(this.red);
		if (redStr.length() == 1)
			redStr = "0" + redStr;
		greenStr = Integer.toHexString(this.green);
		if (greenStr.length() == 1)
			greenStr = "0" + greenStr;
		blueStr = Integer.toHexString(this.blue);
		if (blueStr.length() == 1)
			blueStr = "0" + blueStr;
		return "#" + redStr + greenStr + blueStr;
	}

	/*************************************************************
	 * This method returns true if the this color is equal to the
	 * other color and returns false otherwise.
	 * @param other The color to be added to this color
	 * @return      Whether or not the two colors are equal
	 *************************************************************/
	public boolean equals(Color139 other)
	{
		return (this.red==other.red) && (this.green==other.green)
		 && (this.blue==other.blue);
	}

	/*************************************************************
	 * The method returns a lighter new Color139 value. Each of
	 * the red, green, and blue components is increased by 32 up
	 * to a maximum of 255.
	 * @return The lighter color
	 *************************************************************/
	public Color139 lighten()
	{
		Color139 newcolor;
		newcolor = new Color139 (this.red + 32, this.green + 32,
		 this.blue + 32);
		return newcolor;
	}

	/*************************************************************
	 * The method returns a darker new Color139 value. Each of
	 * the red, green, and blue components is decreased by 32 down
	 * to a minimum of 0.
	 * @return The darker color
	 *************************************************************/
	public Color139 darken()
	{
		Color139 newcolor;
		newcolor = new Color139 (this.red - 32, this.green - 32,
		 this.blue - 32);
		return newcolor;
	}

	/*************************************************************
	 * The method returns a brighter new Color139 value. Each of
	 * the red, green, and blue components is increased by half the
	 * difference between 256 and the component value.  For example,
	 * the color (255, 128, 32) would become 
	 * (255+0, 128+64, 32+112) == (255, 192, 144).
	 * @return The brighter color
	 *************************************************************/
	public Color139 brighten()
	{
		Color139 newcolor;
		int   redInc;
		int   greenInc;
		int   blueInc;

		redInc = (256 - this.red) / 2;
		blueInc = (256 - this.blue) / 2;
		greenInc = (256 - this.green) / 2;

		newcolor = new Color139 (this.red + redInc, this.green + greenInc,
		 this.blue + blueInc);
		newcolor = new Color139 ((int)(this.red * 1.2), (int)(this.green * 1.2),
		 (int)(this.blue * 1.2));
		return newcolor;
	}

	/*************************************************************
	 * The method returns a dimmer new Color139 value. Each of
	 * the red, green, and blue components is by 2 dividing it
	 * by 2.
	 * @return The dimmer color
	 *************************************************************/
	public Color139 dim()
	{
		Color139 newcolor;
		newcolor = new Color139 (this.red / 2, this.green / 2,
		 this.blue / 2);
		newcolor = new Color139 ((int)(this.red / 1.2), (int)(this.green / 1.2),
		 (int)(this.blue / 1.2));
		return newcolor;
	}

	/*************************************************************
	 * The method returns a new Color139 value that is the sum of
	 * this color and the other color. The value of the red components of
	 * the two colors are added as are the green and blue components.
	 * Any result greater than 255 is set to 255.
	 * @param other The color to be added to this color
	 * @return      The sum of the two colors
	 *************************************************************/
	public Color139 add(Color139 other)
	{
		Color139 newcolor;
		newcolor = new Color139 (this.red + other.red, this.green + other.green,
		 this.blue + other.blue);
		return newcolor;
	}

	/*************************************************************
	 * The method returns a new Color139 value that is the difference between
	 * this color and the other color. The value of the red components of
	 * the other color is subtracted from the red component of this color.
	 * The green and blue components are calculated similarly.
	 * Any result less than 0 is set to 0.
	 * @param other The color to be subtracted from this color
	 * @return      The sum of the two colors
	 *************************************************************/
	public Color139 sub(Color139 other)
	{
		Color139 newcolor;
		newcolor = new Color139 (this.red - other.red, this.green - other.green,
		 this.blue - other.blue);
		return newcolor;
	}
}
