Ask Question
5 July, 20:07

A Color class has a method getColorName that returns a string corresponding to the common name for the color, e. g., yellow, blue, white, etc. If there is no common name associated with the color, null is returned. 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. Write the method getColorName of AlphaChannelColor, that overrides the method in the Color class. AlphaChannelColor's getColorName should return the name of the color (obtained from the getColorName method of Color) prefixed with the word 'opaque' if the alpha value is less than 100, 'semi-transparent' if the alpha value is otherwise less than 200, and 'transparent' otherwise (separate the prefix from the color name by a blank). If the color has no name, the method should return "opaque color", "semi-transparent color", or "transparent color", according the the same alpha values as above.

+4
Answers (1)
  1. 5 July, 23:47
    0
    public String getColorName () {

    String name = super. getColorName ();

    if (name = = null) name = "color";

    if (alpha < 100)

    return "opaque " + name;

    else if (alpha < 200)

    return "semi-transparent " + name;

    return "transparent " + name;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “A Color class has a method getColorName that returns a string corresponding to the common name for the color, e. g., yellow, blue, white, ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers