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(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.
*and here is what I have so far, I'm sure there are errors, I'm still new at this.*
Expand|Select|Wrap|Line Numbers
- 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);
- }
- }
Expand|Select|Wrap|Line Numbers
- 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