Programming Work - public int compareTo(Color other return...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Color { // instance data private int red; private int green; private int blue; public Color() { red = green = blue = 255; } public Color(int r,int g,int b) { red = valid(r); green = valid(g); blue = valid(b); } public String toString() { return "(" + red + "," + green + "," + blue + ")"; } public String htmlHex() { return "#" + hexify(red) + hexify(green) + hexify(blue); } public void deltaRed(int c) { red = valid(c + red); } public void deltaGreen(int c) { green = valid(c + green); } public void deltaBlue(int c) { blue = valid(c + blue); } public int saturation() { return red + blue + green;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } public int compareTo(Color other) { return other.saturation() - saturation(); } public boolean equals(Color other) { return red == other.red && green == other.green && blue == other.blue; } public static Color black() { Color c = new Color(0, 0, 0); return c; } public static int valid(int c) { if (c > 255) return 255; else if (c < 0) return 0; else return c; } public static String hexify(int n) { String ns = Integer.toHexString(n).toUpperCase(); if (ns.length() == 1) ns = "0" + ns; return ns; } }...
View Full Document

This note was uploaded on 04/03/2010 for the course COMPSCI 600.107 taught by Professor Houlahan during the Spring '08 term at Johns Hopkins.

Page1 / 2

Programming Work - public int compareTo(Color other return...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online