getting errors in java for an assignment

Reply

Join Date: Nov 2008
Posts: 3
Reputation: mangoxoxo is an unknown quantity at this point 
Solved Threads: 0
mangoxoxo mangoxoxo is offline Offline
Newbie Poster

getting errors in java for an assignment

 
0
  #1
Nov 19th, 2008
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:
  1. import java.awt.Color;
  2. public class PhotoOps{
  3. private Picture _picture;
  4.  
  5. public PhotoOps(String n) {
  6. String _filename="/eng/class/notes/cse113/intro-prog-java/mediasources" + n;
  7. _picture=new Picture(_filename);
  8. _picture.show();
  9. }
  10.  
  11.  
  12. public double colorDistance(Color newColor, Color targetColor) {
  13. Pixel [] pixels=_picture.getPixels();
  14. int i=0;
  15. while (i<pixels.length){
  16. newColor(pixels[i]);
  17. targetColor(pixels[i]);
  18. i=i+1;
  19. double redDistance = targetColor.getRed() - newColor.getRed();
  20. double greenDistance = targetColor.getGreen() - newColor.getGreen();
  21. double blueDistance = targetColor.getBlue() - newColor.getBlue();
  22. double distance = Math.sqrt(redDistance * redDistance +
  23. greenDistance * greenDistance +
  24. blueDistance * blueDistance);
  25. }
  26. }
  27. }

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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,355
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: getting errors in java for an assignment

 
0
  #2
Nov 19th, 2008
You still need to create the public Color newColor(Pixel pixel) method that you are attempting to use.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: mangoxoxo is an unknown quantity at this point 
Solved Threads: 0
mangoxoxo mangoxoxo is offline Offline
Newbie Poster

Re: getting errors in java for an assignment

 
0
  #3
Nov 19th, 2008
where would that go?
i put it here
  1. public Color newColor(Pixel pixel);
  2. public double colorDistance(Color newColor, Color targetColor) {
  3. Pixel [] pixels=_picture.getPixels();
  4. int i=0;
  5. while (i<pixels.length){
  6. newColor(pixels[i]);
  7. targetColor(pixels[i]);
  8. i=i+1;

and it must be wrong because i'm getting an error
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,355
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: getting errors in java for an assignment

 
0
  #4
Nov 19th, 2008
Because all you've done is declare the method, you also need to define it. That method needs to actually do something.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 3
Reputation: mangoxoxo is an unknown quantity at this point 
Solved Threads: 0
mangoxoxo mangoxoxo is offline Offline
Newbie Poster

Re: getting errors in java for an assignment

 
0
  #5
Nov 19th, 2008
This gets so confusing to me so sorry if I ask stupid questions..but where and how do I define the method?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC