Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a file called picture.java in which a method called scaleUp is located. T

ID: 3622447 • Letter: I

Question

I have a file called picture.java in which a method called scaleUp is located. This method acts upon a picture object and increases its size.

This is what the method looks like:

public Picture scaleUp(int numTimes)
{
Picture targetPicture = new Picture(this.getWidth() * numTimes,
this.getHeight() * numTimes);
Pixel sourcePixel = null;
Pixel targetPixel = null;
int targetX = 0;
int targetY = 0;

for (int sourceX = 0; sourceX < this.getWidth(); sourceX++)
{
for (int sourceY=0;sourceY < this.getHeight(); sourceY++)
{
sourcePixel = this.getPixel(sourceX,sourceY);
for (int indexY = 0; indexY < numTimes; indexY++)
{
for (int indexX = 0; indexX < numTimes; indexX++)
{
targetX = sourceX * numTimes + indexX;
targetY = sourceY * numTimes + indexY;
targetPixel = targetPicture.getPixel(targetX,
targetY);
targetPixel.setColor(sourcePixel.getColor());
}
}
}
}

return targetPicture;
}

What I'm trying to do is create another .java file in which I create a class that would contain a main method which invokes the scaleUp method from the Picture.java file, but I'm not sure how to do this.

This is what I have so far:

public class Lab7

{
public static void main(String[] args)  

{  

int numTimes;  

numTimes = 2;  

String fileName = FileChooser.pickAFile();  

Picture somePic = new Picture(fileName);  

somePic = somePic.scaleUp(numTimes);  

}

}

Thanks in advance.

Explanation / Answer

Place the 2 java files in same folder and import the class of first java file in program to be used. Compile the 2 file.