hey i got a problem finishing this code which has been driving me INSA

really need help on the last part of the code.. brighter and darker me

Page 1 of 1

2 Replies - 476 Views - Last Post: 17 November 2008 - 10:48 AM Rate Topic: -----

#1 i_love_java  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-November 08

hey i got a problem finishing this code which has been driving me INSA

Posted 17 November 2008 - 10:22 AM

/*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 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 :code:

This post has been edited by pbl: 17 November 2008 - 07:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: hey i got a problem finishing this code which has been driving me INSA

#2 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: hey i got a problem finishing this code which has been driving me INSA

Posted 17 November 2008 - 10:41 AM

In the Brighter/Darker methods, make use of the methods setRed/setGreen/setBlue.

The values to be set are the minimum of the old value * 1.42 (rounded) or 255. Make use of the math functions that exist in the math-library in java. Similarly for darker.

Do this for red, gree and blue.

Ex,

public void brighter() {
setRed(Math.min(Math.round(r*1.42), 255));
// similar for green
// similar for blue
}

The code is not quite what you need but maybe it will give you some idea.

This post has been edited by Gloin: 17 November 2008 - 10:46 AM

Was This Post Helpful? 0
  • +
  • -

#3 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2734
  • View blog
  • Posts: 11,513
  • Joined: 20-September 08

Re: hey i got a problem finishing this code which has been driving me INSA

Posted 17 November 2008 - 10:48 AM

Quote

public boolean equals( Colour col )


should be

public boolean equals(Object o)


What in particular are you having problems with?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1