*should be achieved by increasing each of this colour’s RGB values by 42% up to a maximum of 255
*(you should carefully consider how to deal with brightening the colour black!!). This method should
*leave the value of the original colour unchanged. If one or more of the triplets is zero, then
*implementing brighter( ) presents a problem (why?). If this is the case, then application of brighter( )
should return a triplet where any zero value is replaced by the value 3.*/
/*The body of the method will need to check initially, if any of the individual values is 0 – then increase
*each by 42% - also be aware that you will need to produce an integer for each of the RGB values.
*(g) 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 this colour’s RGB values by 30%*/
//
class Colour
{
private int r;
private int g;
private int b;
public Colour (int red, int green, int blue)
{
r = red;
g = green;
b = blue;
}
public Colour (Colour c)
{
r = c.r;
g = c.g;
b = c.b;
}
public int getRed()
{
return r;
}
public int getGreen()
{
return g;
}
public int getBlue()
{
return b;
}
public void setRed( int newRedValue )
{
assert (newRedValue >= 0) && (newRedValue <= 255) : "value of red out of range: " + newRedValue;
r = newRedValue;
}
public void setGreen( int newGreenValue )
{
assert (newGreenValue >= 0) && (newGreenValue <= 255) : "value of green out of range: " + newGreenValue;
g = newGreenValue;
}
public void setBlue( int newBlueValue )
{
assert (newBlueValue >= 0) && (newBlueValue <= 255) : "value of blue out of range: " + newBlueValue;
b = newBlueValue;
}
public boolean equals( Colour col )
{
return ( this.r == col.r) && (this.g == col.g) && (this.b == col.B);
}
@Override
public String toString()
{
return "Colour ( " + r + ", " + g + ", " + b + ", )";
}
public Colour brighter()
{
return Current Colour r = 17, g = 192, b = 215;
}
public Colour darker()
{
return
}
}
*Edited to add the [ code] tags. Please
This post has been edited by pbl: 17 November 2008 - 07:48 PM

New Topic/Question
Reply




MultiQuote




|