Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java assignment help!

 
jessica Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's for an assignment in my Intro to Comp Prog. so I'm definitely a beginner. Here's the assignment, I've been working on it for over a week, and it seems like it would be simple, but I cannot figure it out..

it's an assignment in DrJava, HERE IT IS:

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.


(this is the part I can't really figure out)
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.

HERE'S WHAT I HAVE SO FAR



AND THE ERRORS I'M GETTING



any help on how I can correct the errors, and complete the assignment would be EXTREMELY appreciated! thanks in advance
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here the explanation of the first two errors... I also recommend that you should only fix one or two compile errors, before recompiling. You can probably do more once you get more experienced.



At line 16, you are calling a newColor() method, which you have not defined.



At line 17, you are calling a targetColor() method, which you have not defined.

Henry
[ November 20, 2008: Message edited by: Henry Wong ]
 
jessica Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I define them?
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jessica Smith:
How do I define them?


If you are referring to the algorithm... it's your program, you tell us.

If you are referring to how to define methods... the same way that you define the ones you did so far, except with different names and parameters.

Henry
 
jessica Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I'm super new at this still so I know these questions probably sound stupid to you, but which parts of my code that I've already done define a method?
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, to directly answer you question, you implemented a method call colorDistance().... but I do have a question.

How did you implement it? You designed a method to call other methods, but you don't know what the other methods are supposed to do?

I can't imagine how it is possible to code something to use something else, and have no idea what that something else is supposed to do -- at minimum, you called it for a reason.

Henry
 
jessica Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Henry Wong:
Well, to directly answer you question, you implemented a method call colorDistance().... but I do have a question.

How did you implement it? You designed a method to call other methods, but you don't know what the other methods are supposed to do?

I can't imagine how it is possible to code something to use something else, and have no idea what that something else is supposed to do -- at minimum, you called it for a reason.

Henry



well I'm not sure that what I have already is correct in the first place..All I was given in the instructions is this:
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.

What I have done so far I have pieced together from previous assignments or examples, so I could have some things in the code that don't belong there in the first place.
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I have done so far I have pieced together from previous assignments or examples, so I could have some things in the code that don't belong there in the first place.


Then it may be best to "comment out" the offending code... To get the program to compile. Then get the algorithm working. And not worry about implementing methods, that you don't know if you need yet.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic