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(Color 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.jpg 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.

WHAT I HAVE SO FAR:

import java.awt.Color;
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);
    }
  }
}

ERRORS I'M GETTING:
2 errors found:
File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java [line: 16]
Error: cannot find symbol
symbol : method newColor(Pixel)
location: class PhotoOps
File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java [line: 17]
Error: cannot find symbol
symbol : method targetColor(Pixel)
location: class PhotoOps

any help would be greatly appreciated!
thanks

You still need to create the public Color newColor(Pixel pixel) method that you are attempting to use.

where would that go?
i put it here

public Color newColor(Pixel pixel);
  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;

and it must be wrong because i'm getting an error

Because all you've done is declare the method, you also need to define it. That method needs to actually do something.

This gets so confusing to me so sorry if I ask stupid questions..but where and how do I define the method?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.