A Color class has three public, integer -returning accessor methods : getRed, getGreen, and getBlue, and three protected, void-returning mutator methods : setRed, setGreen, setBlue, each of which accepts an integer parameter and assigns it to the corresponding color component.

A Color class has three public, integer -returning accessor methods : getRed, getGreen, and getBlue, and three protected, void-returning mutator methods : setRed, setGreen, setBlue, each of which accepts an integer parameter and assigns it to the corresponding color component.

LANGUAGE: JAVA

CHALLENGE:

A Color class has three public, integer -returning accessor methods : getRed, getGreen, and getBlue, and three protected, void-returning mutator methods : setRed, setGreen, setBlue, each of which accepts an integer parameter and assigns it to the corresponding color component.
The class , AlphaChannelColor– a subclass of Color– has an integer instance variable , alpha, containing the alpha channel value , representing the degree of transparency of the color. AlphaChannelColor also has a method named dissolve (void-returning, and no parameters ), that causes the color to fade a bit . It does this by incrementing (by 1) all three color components (using the above accessor and mutator methods ) as well as the alpha component value .

Write the dissolve method .

SOLUTION:

public void dissolve() {
    setRed(getRed()+1);
    setGreen(getGreen()+1);
    setBlue(getBlue()+1);
    alpha++;
}

Add comment