The_Big_Man Posted November 2, 2005 Posted November 2, 2005 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(); }}
Dutchdre Posted November 7, 2005 Posted November 7, 2005 (edited) Why would you make this?It's already included in java:http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Color.htmlbtw: 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 Edited November 7, 2005 by Dutchdre
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now