programming assignment - colorDistance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mangoxoxo
    New Member
    • Nov 2008
    • 3

    programming assignment - colorDistance

    Hey I'm not sure if this is where I should be asking this but I'm going to ask anyway.

    I'm doing an assignment for my Intro to Comp Programming class. This is the assignment:

    Define a class named PhotoOps. Like you did in your last programming assignment,
    define the class with a String instance variable named _filename, and Picture
    instance variable named _picture. Define the constructor so that it accepts a String
    as an argument; the String passed in should be the name of a file in the /eng/class/notes/cse113/intro-prog-java/mediasources/
    directory. Assign to _filename the result of combining the String
    “/eng/class/notes/cse113/intro-prog-java/mediasources/” with
    the constructor’s String parameter, using “+” to concatenate the two Strings.

    Also as you did last week, define a void method named loadPicture as a method
    with an empty parameter list. When called, this method must create a new Picture
    object using _filename as the argument in the constructor call; define the method in
    such a way that after creating and loading the Picture object, it is “shown”. You may
    copy this method from your solution to programming assignment #3 if you wish. Modify
    the constructor to PhotoOps so that it automatically calls loadPicture.

    *THIS IS THE PART I'M CONFUSED ABOUT*

    Now onto the new part of this programming assignment. In section 6.1 of the text, the
    authors explain how to compute the distance between two colors. They write,
    The Pixel class has an object method colorDistance(C olor color)
    which returns the distance between the color in the current Pixel object and the
    passed color.
    Write a method which takes three arguments, a Color, targetColor, and an int, distance,
    and a second Color, newColor. Define the method so that it changes the color each
    Pixel in _picture that is within distance of the targetColor to newColor.

    Now experiment with this method and the redMotorcycle.j pg picture to find a good value
    for the distance from java.awt.Color. RED which will change the color of the
    motorcycle’s red parts to java.awt.Color. WHITE. Write the value you think works best
    into a comment for the method you wrote.

    *and here is what I have so far, I'm sure there are errors, I'm still new at this.*

    Code:
    public class PhotoOps{
      private Picture _picture;
      
      public PhotoOps(String n) {
        String _filename="/eng/class/notes/cse113/intro-prog-java/mediasources" + n;
        _picture=new Picture(_filename);
        _picture.show();
      }
      
      
      public double colorDistance(Color newColor, Color targetColor) {
        Pixel [] pixels=_picture.getPixels();
        int i=0;
        while (i<pixels.length){
          newColor(pixels[i]);
          targetColor(pixels[i]);
          i=i+1;
       double redDistance = targetColor.getRed() - newColor.getRed();
       double greenDistance = targetColor.getGreen() - newColor.getGreen();
       double blueDistance = targetColor.getBlue() - newColor.getBlue();
       double distance = Math.sqrt(redDistance * redDistance + 
                                   greenDistance * greenDistance +
                                   blueDistance * blueDistance);
       
      }
    }
    these are the errors I got:
    Code:
    4 errors found:
    File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java  [line: 11]
    Error: cannot find symbol
    symbol  : class Color
    location: class PhotoOps
    File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java  [line: 11]
    Error: cannot find symbol
    symbol  : class Color
    location: class PhotoOps
    File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java  [line: 15]
    Error: cannot find symbol
    symbol  : method newColor(Pixel)
    location: class PhotoOps
    File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java  [line: 16]
    Error: cannot find symbol
    symbol  : method targetColor(Pixel)
    location: class PhotoOps
    I could just use some guidance here on how I can complete this assignment, I always leave out or mess up little details and I've been trying forever. Thanks to whoever reads this!
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Did you forget to include the correct 'import' statements? For instance, do you have:

    Code:
    import java.awt.Color;
    so that your program will recognize Color as a class?

    Comment

    • mangoxoxo
      New Member
      • Nov 2008
      • 3

      #3
      where would that go in the code I have?

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Originally posted by mangoxoxo
        where would that go in the code I have?
        Right at the top - imports are the first thing you do in a Java program.

        Greetings,
        Nepomuk

        Comment

        • mangoxoxo
          New Member
          • Nov 2008
          • 3

          #5
          Thank you so much!

          I'm still having these errors though

          File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java [line: 17]
          Error: cannot find symbol
          symbol : method newColor(Pixel)
          location: class PhotoOps
          File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java [line: 18]
          Error: cannot find symbol
          symbol : method targetColor(Pix el)
          location: class PhotoOps

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by mangoxoxo
            Thank you so much!

            I'm still having these errors though

            File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java [line: 17]
            Error: cannot find symbol
            symbol : method newColor(Pixel)
            location: class PhotoOps
            File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java [line: 18]
            Error: cannot find symbol
            symbol : method targetColor(Pix el)
            location: class PhotoOps
            Read the error messages, they're emitted for that reason: on line 17 of that file
            the symbol 'newColor(Pixel )' could not be found, i.e. that method with that
            particular parameter type could not be found anywhere in the PhotoOps class.

            Read your source file: is that method present? No it isn't; the compiler never lies.

            The same reasoning applies to the second compiler message. Learn how to read
            them; don't panic; don't post them to any forum but correct your mistake.

            kind regards,

            Jos

            Comment

            Working...