Reputation: 1
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"
Upvotes: 0
Views: 315
Reputation: 1345
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)
}
Upvotes: 6
Reputation: 463
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
Upvotes: 0