Painting Class Help Java

Discussion in 'Software' started by The_Lone_Wolf, Nov 2, 2005.

  1. The_Lone_Wolf

    The_Lone_Wolf Private E-2

    This is Java btw. Can someone give me some help to do these points. part 1 was the colour class which i have almost complete apart from few problems but i have no idea how to go about this class:

    1) an appropriate set of constructors for the Painting class
    2) an appropriate set of accessor methods
    3) an appropriate mutator, setColour( ... ), that sets a given pixel to a specified colour
    4) a method setWash( ... ) which fills all the pixels in a Painting object with the same specified colour

    if someone could give me a start to these then i could probably get this however i dont have a clue about this.
     
  2. QuickSilver

    QuickSilver Corporal

    This looks like a typical set of questions for someone learning Object Oriented development...

    It looks to me like you've been asked to create a Painting Class with a set of constructors, typical get/set methods and some special methods... Im guessing you've left out the general description of what the class is meant to do.

    Each question will be an expansion on the previous question, so question 1s solution will be a subset of question 2s solution etc. You'll take a basic class with a constructor for question 1, add more and more methods until its complete at the end of question 4...

    I assume you understand the concepts of OO? What in particular are you struggling with or do you not understand?
     
  3. The_Lone_Wolf

    The_Lone_Wolf Private E-2

    Your quite correct its object orientated programming. We have just started learning it and have been set this coursework and this is my very first time learning java.

    We have to do the colour class followed by the painting class and then the apps to run it all. I have done the colour class of which i hope it correct I have trouble understand the painting class and where to start e.g the points. For the first one the structure and some of the points were given to help start us off. this is my colour class that i have done so far although it has 68 errors in it which is doing my head in. Also below is the spec on what is needed to be done for it and i think i have covered all of it.

    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%

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

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds