0

I am making a project where I need to create a method that will be create two different purple colored splotches which will be called in a different program. This is the code I have:

public class PaintablePicture extends Picture
{
 public PaintablePicture(String fileName)
 {super(fileName);}

  public void purpleSplotch(int x,int y)
  {
  int x=0;
  int y=1;
  while(x < x*2)
  while(y < y*3)

 {
    Color purple = new Color(175, 0, 175);
   Pixel pixRef;
   pixRef= this.getPixel(x,y);
  pixRef.setColor(purple);

  }
 return;

}

In the other program where I am calling it I have:

  FileChooser.pickMediaPath();
  PaintablePicture pRef;
  pRef = new PaintablePicture(FileChooser.pickAFile());
  pRef.purpleSplotch(10,20);
  pRef.explore();

I have to make a while loop that uses variables in order to make the splotches and I don't understand help me please I get the "Error: Duplicate local variable x"

2 Answers 2

6

You are passing the value "x" and "y" in the method

public void purpleSplotch(int x,int y)

and again declaring it locally within the method

int x=0;
int y=1;

That is why you are getting that error.

Declare another variable inside the method instead of x and y again.

Make the following changes:

public void purpleSplotch(int x,int y)
  {
  int x1=0;
  int y1=1;
  while(x1 < x*2)
  while(y1 < y*3)
}
2
  • okay but now dr.Java won't load anything when I run it, and I really need to see if it works because there's still another thing I need to program.
    – neech
    Commented Mar 5, 2013 at 2:22
  • 2
    If you were able to resolve the duplicate variable error, please accept the answer
    – Abi
    Commented Mar 5, 2013 at 2:54
0

First of all, you have to see that you have two parameters, the first called x and the second y, and inside the method, you are also defining variables with the same name. Try changing the name of the parameters or the name of the local variables

1
  • clearly I am a beginner and I am changing my major after this semester. can you give me an example?
    – neech
    Commented Mar 5, 2013 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.