A Color class has a constructor that accepts three integer parameters : red, gre
ID: 3571267 • Letter: A
Question
A Color class has a constructor that accepts three integer parameters : red, green and blue components in the range of 0 ... 255 with 0 representing no contribution of the component and 255 being the most intense value for that component .
The effect of full or semi-transparency can be achieved by adding another component to the color called an alpha channel. This value can also be defined to be in the range of 0...255 with 0 representing opaque or totally non-transparent, and 255 representing full transparency.
Define a class AlphaChannelColor to be a subclass of the Color class . AlphaChannelColor should have the following: - an integer instance variable alpha - a constructor that accepts four parameters : red, green, blue and alpha values in that order. The first three should be passed up to the Color class ' constructor , and the alpha value should be used to initialize the alpha instance variable . - a getter (accessor) method for the alpha instance variable
SUBMIT
Explanation / Answer
/* Color.java */
public class Color {
int green,red,blue;
Color(int red,int green,int blue)
{
this.red=red;
this.green=green;
this.blue=blue;
}
}
/* AlphaChannelColor.java */
public class AlphaChannelColor extends Color {
int alpha;//local variable
public static void main(String[] args) {
// Color c=new Color(l_red,l_green,l_blue);
}
AlphaChannelColor(int l_red,int l_green,int l_blue,int l_alpha)//4 parameter Constructor
{
super(l_alpha, l_alpha, l_alpha);//Calling Super class Color class constructor
this.red=l_red;
this.green=l_green;
this.blue=l_blue;
this.alpha=l_alpha;
}
public int getAlpha()//Getter method for alpha
{
return alpha;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.