Question
Store final static Color variables named BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, and WHITE (for RGB values, see this chart). For example: static final
Store final static Color variables named BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, and WHITE (for RGB values, see this chart). For example:
static final Color RED = new Color(255, 0, 0); |
Create 3 private int variables named red, green, and blue (the color components of a Color) as instance variables.
Create the following:
A constructor that takes 3 int variables as parameters. This constructor creates a Color object with the specified RGB component values. If a component value less than 0 is specified, that component is set to 0. If a component value greater than 255 is specified, that component value is set to 255.
A method called toString that takes no parameters. This method returns a string representation of the color in the form #rrggbb where rr, gg, and bb are the red, green, and blue component values expressed as hexadecimal digits. View the Integer api to find a method that converts an integer value to hexadecimal (base 16).
Example (result shown in red below the code)
Color c = new Color(255, 0, 0); c.toString(); |
#ff0000
A method called add that takes a Color object as a parameter. This method returns a new Color value that is the sum of this color and the color specified as a parameter. The value of the red components of the two colors are added (The same for the green and blue). Any result greater than 255 is set to 255.
Example (result shown in red below the code)
Color c = new Color(25,100,500); Color newColor = c.add(Color.BLUE); return newColor; |
Color(25,100,255)
A method called sub that takes a Color object as a parameter. This method returns a new Color value that is the difference between this color and the color specified as a parameter. The value of the red components of the two colors are subtracted(The same for the green and blue). Any result less than 0 is set to 0.
Example (result shown in red below the code)
Color c = new Color(25,100,50); Color newColor = c.sub(new Color(35, 50, 10)); |
Color(0,50,40);
A method called dim that takes no parameters. This method returns a dimmer new Color value. Each of the red, green, and blue components are decreased by 20%. If any of the reduced components is a fractional numbers provide the floor value for that component.
Example (result shown in red below the code)
Color c = new Color(25,100,50); Color a = c.dim(); |
Color(20,80,40)
A method called darken that takes no parameters The method returns a darker new Color value. Each of the red, green, and blue components is decreased by 32 down to a minimum of 0.
Example (result shown in red below the code)
Color c = new Color(25,100,50); c.darken(); |
Color(0,68,18)
A method called equals that takes a Color object as a parameter. This method returns true if this color is equal to the Color object and returns false if it is not equal.
Example (result shown in red below the code)
Color c = new Color(255,255,0); c.equals(Color.YELLOW); |
true
A method called lighten that takes no parameters. The method returns a lighter new Color value. Each of the red, green, and blue components is increased by 32 up to a maximum of 255.
Example (result shown in red below the code)
Color c = new Color(100,255,50); c.lighten(); |
Color(132,255,82)
A method called brighten that takes no parameters. The method returns a brighter new Color value. Each of the red, green, and blue components is increased by 20%.
Example (result shown in red below the code)
Color c = new Color(100,255,50); c.brighten(); |
Color(120,255,60)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started