A Color class has three integer color component instance variable: red, green, and blue. Write a toString method for this class . It should return a string consisting of the three color components (in the order red, green, blue) within parentheses, separated by commas, with a ‘#’ prefix e.g. #(125, 30, 210)

LANGUAGE: JAVA

CHALLENGE:

A Color class has three integer color component instance variable: red, green, and blue.
Write a toString method for this class . It should return a string consisting of the three color components (in the order red, green, blue) within parentheses, separated by commas, with a ‘#’ prefix e.g. #(125, 30, 210)

SOLUTION:


public String toString() {
   return "#(" + red + "," + green + "," + blue + ")";
}