A4Methods_Solutions - / Assignment 4 import java.awt.*; /*...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 // Assignment 4 import java.awt.* /** Contains static methods of assignment A4 */ public class A4Methods { /** = the complement of color rgb. */ public static Color complementRGB(Color rgb) { return new Color(255 - rgb.getRed(), 255 - rgb.getGreen(), 255 - rgb.getBlue()) } /** = s truncated (if necessary) to its first 5 characters. */ public static String truncateTo5(String s) { return (s.length() < 5 ? s : s.substring(0,5)) } /** = RGB value rgb in the form "[R, G, B]". Precondition: each of the rgb values is an integer in the range 0. .255. */ public static String toString(Color rgb) { return "[" + rgb.getRed() + ", " + rgb.getGreen() + ", " + rgb.getBlue() + "]" } /** = CMYK value cmyk in the form "[C, M, Y, K]". In the output, each of C, M, Y, and K should take at most 5 characters. public static String toString(CMYK cmyk) { return "[" + truncateTo5(Double.toString(cmyk.c)) + ", " + truncateTo5(Double.toString(cmyk.m)) + ", " + truncateTo5(Double.toString(cmyk.y)) + ", " + truncateTo5(Double.toString(cmyk.k)) + "]"
Background image of page 1

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

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

This homework help was uploaded on 02/20/2009 for the course CS 100 taught by Professor Fan/vanloan during the Spring '07 term at Cornell University (Engineering School).

Page1 / 6

A4Methods_Solutions - / Assignment 4 import java.awt.*; /*...

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