A colour can be modelled as an RGB triplet with three integer values, each in the range 0 to 255 which correspond to the specified red, green, and blue components in that colour. The higher the value of one of these values, the brighter that component is. The colour white corresponds to the RGB triplet (255, 255, 255) while black is specified by (0, 0, 0). Other principal colours and their corresponding RGB values are: red (255, 0, 0 ) ; blue ( 0, 0, 255 ) ; cyan (0, 255, 255) ; green (0, 255, 0) ; grey (128, 128, 128); magenta (255, 0, 255) and yellow (255, 255, 0). Any attempt to create a colour using a value outside the range is an error.
1) Define appropriate instance variables for the class Colour
2) Define a set of appropriate constructors for this class
3) Provide "constant" values for each of the nine principal colours listed above that will enable any application that needs to use these colours, say "yellow" to write Colour.yellow etc
4) Define appropriate accessor and setter methods for this class
5) Provide a boolean-valued operation that checks whether two Colour objects have the same value
6) Override the inherited String toString() method to provide an appropriate String representation of a Colour object
7) Provide a method mix() which takes two colours and "mixes" them to produce a new colour whose RGB values are obtained by averaging the individual colour components, for example mixing (20, 30, 40) with (180, 60, 95) produces the colour (100, 45, 67)
8) Provide a method brighter() which creates a new Colour that is a brighter version of this Colour - this should be achieved by increasing each of the current colour's RGB values by 42% up to a maximum of 255
9)Provide a method darker() which creates a new Colour that is a darker version of this Colour - this should be achieved by decreasing each of the current colour's RGB values by 30%.
I have covered points 1 to 5 (hopefully) but need help for 6 to9.
class Colour
{
private static final int MAX = 255;
private static final int MIN = 0;
private int red;
private int green;
private int blue;
public Colour()
{
red = 125;
green = 55;
blue = 66;
}
public Colour( int r1, int g2, int b3 )
{
red = r1;
green = g2;
blue = b3;
}
public Colour( int c )
{
red = c;
green = c;
blue = c;
}
public int getRed()
{
return red;
}
public int getGreen()
{
return green;
}
public int getBlue()
{
return blue;
}
public Colour(int r1, int g2, int b3)
{
this.r1 = r1;
this.g2 = g2;
this.b3 = b3;
}
public boolean equals(Colour n)
{
return ( (this.r1 == c.n1) && (this.g2 == c.g2) && (this.b3 == c.b3) ) || ( (this.r1 == c.r1) && (this.g2 == c.g2) && (this.b3 == c.b3));
}
public String toString()
{
return "Red
}
can you tell me if so far this is correct and on the write track?

New Topic/Question
Reply



MultiQuote



|