473,626 Members | 3,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

programming assignment - colorDistance

3 New Member
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(C olor 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.j pg 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 2678
Ganon11
3,652 Recognized Expert Specialist
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
mangoxoxo
3 New Member
where would that go in the code I have?
Nov 19 '08 #3
Nepomuk
3,112 Recognized Expert Specialist
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
mangoxoxo
3 New Member
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(Pix el)
location: class PhotoOps
Nov 19 '08 #5
JosAH
11,448 Recognized Expert MVP
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(Pix el)
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
3960
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 size n. There are n!/(s!(n-s)!) ways to do this. Donald E. Knuth gives several methods (algorithms) to generate all the s-combinations in . In such procedure-oriented way, each s-combination is processed while it's being generated. In some
12
1657
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 with it, but it looks like bad programming. :) class MyClass { public: //...
4
1607
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 within C itself. Just a bit lost as to where to start. do i initialise a linked list to compare the two arrays or what?
134
7959
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 increasingly been using scripting languages (especially Python and Bourne shell) which offer the same speed and yet are far more simple and safe to use. I can no longer understand why anyone would willingly use C to program anything but the lowest...
7
1501
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 and the best method would be to save a template or other etc. I also know that it's ok to use other people's code to help you do something, but wouldn't it be best to re-type the code or study it until YOU learn how to do it and you actually...
5
2334
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 (no pun intended) to further information. -- There's no place like ~! David Delony E-mail: ickyelf@gmail.com Blog: http://ddelony.livejournal.com
23
3640
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, I have 3 set of quizzes that anyone is welcome to try online for free. Questions on C quizzes are rather easy to solve for Professional C programmers yet for those who are taking C as a first programming course will find these useful in assesment...
1
1826
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 do I make it loop and count/store the responses until the user enters "N" at strAnswer=Console.readline? Where/what loop would I use? Module Module1 Sub Main() Dim strAnswer As String Console.WriteLine("Do you want to...
2
11362
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 that checks to see if a date entered by the user is a valid date in the second millenium. A skeleton of the program is in Dates.java. Open this program and save it to your directory. As indicated by the comments in the program, fill in the following: ...
0
8268
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8202
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8641
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.