MSFN Forum: Colour Class Help Java - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Colour Class Help Java Rate Topic: -----

#1 User is offline   The_Big_Man 

  • Group: Members
  • Posts: 2
  • Joined: 30-October 05

Posted 02 November 2005 - 05:40 AM

I have these points to cover and i have done the coding for it . Could someone check it to see if so far its correct and i have have done everything?

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%

class Colour
{

	public static final Colour black = new Color(0,0,0); 
	public static final Colour red = new Colour(255,0,0);
	public static final Colour blue = new Colour(255,0,0);
	public static final Colour cyan = new Colour(0,255,255);
	public static final Colour green = new Colour(0,255,0);
	public static final Colour grey = new Colour(128,128,128);
	public static final Colour magenta = new Colour(255,0,255);
	public static final Colour yellow = new Colour(255,255,0);
 
	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 n )
   {
	  red = n;
	  green = n;
	  blue = n;
   }


   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 void Mix(Colour c1, Colour c2)
{
	this.red = (c1.red + c2.red) / 2;
	this.green = (c1.green + c2.green) / 2;
	this.green = (c1.blue + c2.blue) / 2;
}

public String toString()
{
	return string.Format("{0},{1},{2}", this.red, this.green, this.blue);
}


public brighter()
  {

  this.red = this.red - (this.red*042);
  this.green = this.green - (this.green *042);
  this.blue = this.blue - (this.blue *042);
  return brighter();
  }

public darker()
  {

  this.red = this.red + (this.red*030);
  this.green = this.green + (this.green *030);
  this.blue = this.blue + (this.blue *030);
  return darker();
  }

}



#2 User is offline   Dutchdre 

  • Newbie
  • Group: Members
  • Posts: 33
  • Joined: 19-January 05

Posted 07 November 2005 - 01:06 PM

Why would you make this?
It's already included in java:
http://java.sun.com/.../awt/Color.html

btw: this looks like an exam, fix it your selfs

--EDIT--
Debug the method's brighter() and darker()...
I guess they never stop because at the last line of each of them you call it self

This post has been edited by Dutchdre: 07 November 2005 - 01:08 PM


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy