| | |
getting errors in java for an assignment
![]() |
•
•
Join Date: Nov 2008
Posts: 3
Reputation:
Solved Threads: 0
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:
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
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:
Java Syntax (Toggle Plain Text)
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. 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
----------------------------------------------
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
•
•
Join Date: Nov 2008
Posts: 3
Reputation:
Solved Threads: 0
where would that go?
i put it here
and it must be wrong because i'm getting an error
i put it here
Java Syntax (Toggle Plain Text)
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.
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
----------------------------------------------
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
![]() |
Similar Threads
- Which language to learn? (Computer Science)
- problem with a java program (Java)
- multithreaded java bubble sort (Java)
- From java to C++ (C++)
- Need help with a very simple Java program (Java)
- I Desperately need help with this assignment!! (Assembly)
- JCreator Build Errors HELP!! (Java)
- Can anybody pls help me writing c or c++ or java code for this program? (C++)
- new to java, and quite lost (Java)
Other Threads in the Java Forum
- Previous Thread: java and mysql question???
- Next Thread: Basic Password Verifier
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






