473,414 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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(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
  1. public class PhotoOps{
  2.   private Picture _picture;
  3.  
  4.   public PhotoOps(String n) {
  5.     String _filename="/eng/class/notes/cse113/intro-prog-java/mediasources" + n;
  6.     _picture=new Picture(_filename);
  7.     _picture.show();
  8.   }
  9.  
  10.  
  11.   public double colorDistance(Color newColor, Color targetColor) {
  12.     Pixel [] pixels=_picture.getPixels();
  13.     int i=0;
  14.     while (i<pixels.length){
  15.       newColor(pixels[i]);
  16.       targetColor(pixels[i]);
  17.       i=i+1;
  18.    double redDistance = targetColor.getRed() - newColor.getRed();
  19.    double greenDistance = targetColor.getGreen() - newColor.getGreen();
  20.    double blueDistance = targetColor.getBlue() - newColor.getBlue();
  21.    double distance = Math.sqrt(redDistance * redDistance + 
  22.                                greenDistance * greenDistance +
  23.                                blueDistance * blueDistance);
  24.  
  25.   }
  26. }
  27.  
these are the errors I got:
Expand|Select|Wrap|Line Numbers
  1. 4 errors found:
  2. File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java  [line: 11]
  3. Error: cannot find symbol
  4. symbol  : class Color
  5. location: class PhotoOps
  6. File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java  [line: 11]
  7. Error: cannot find symbol
  8. symbol  : class Color
  9. location: class PhotoOps
  10. File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java  [line: 15]
  11. Error: cannot find symbol
  12. symbol  : method newColor(Pixel)
  13. location: class PhotoOps
  14. File: /Users/jsmith/Desktop/drjava-stable-20050814-2234-osx/CSE113/PhotoOps.java  [line: 16]
  15. Error: cannot find symbol
  16. symbol  : method targetColor(Pixel)
  17. location: class PhotoOps
  18.  
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!
Nov 19 '08 #1
5 2664
Ganon11
3,652 Expert 2GB
Did you forget to include the correct 'import' statements? For instance, do you have:

Expand|Select|Wrap|Line Numbers
  1. import java.awt.Color;
so that your program will recognize Color as a class?
Nov 19 '08 #2
where would that go in the code I have?
Nov 19 '08 #3
Nepomuk
3,112 Expert 2GB
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
Nov 19 '08 #4
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(Pixel)
location: class PhotoOps
Nov 19 '08 #5
JosAH
11,448 Expert 8TB
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(Pixel)
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
Nov 19 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bo Xu | last post by:
Object of Combination By Bo Xu Introduction A combination of n things, taken s at a time, often referred as an s-combination out of n, is a way to select a subset of size s from a given set of...
12
by: John Fullman | last post by:
I do this in several large classes to avoid rewriting copy ctr code. It seems to work okay, but I was wondering if I might be shooting myself in the foot later... I can't think of anything wrong...
4
by: janconway | last post by:
Hey, kinda bit lost with the lab assignment in college. any tips would be really appreciated. basically we were given a flex file and we've to modify it to see if a string is a keyword or identifier...
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
7
by: Michael | last post by:
Hey, I'm, I guess, an itermediate programmer and I have a question about learning any programming language. I understand that as a programmer you're going to probably constantly be re-writing code...
5
by: David Delony | last post by:
I've hacked on shell and Perl and now I want to get seriously into C. I got bogged down in K & R, but I realized that I need to know more about the low-level computing stuff. I'd like some pointers...
23
by: Dexter | last post by:
My site is home to series of quizzes ranging from Accounting, Business, Math to programming languages. These are multiple choice type questions and you get a score card at end. For C language, ...
1
by: trav4 | last post by:
I have an assignment for school and I am new to programming. For the assignment I need to make a survey with at least 4 choices that uses 2 arrays. It must be done in a console application. How...
2
by: mshroom12 | last post by:
I am having trouble with the following project on hand. I use Eclipse to do my work in Java. This is what I'm supposed to complete. Date Validation In this exercise you will write a program...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.