Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Colour Class Help Java

Featured Replies

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();
}

}

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.