public void doStuff() { for ( int x=0; x < pic.getWidth(); x++ ) { for (int y=0;
ID: 3812106 • Letter: P
Question
public void doStuff()
{
for ( int x=0; x < pic.getWidth(); x++ )
{
for (int y=0; y < pic.getHeight(); y++ )
{
Pixel p = pic.getPixel( x, y );
p.setColor( new Color( 100, 100, 100 ) );
}
}
}
public static void main( String[] args )
{
Picture pic = new Picture( "frog.jpg" );
pic.doStuff();
pic.show();
}
----------------------------------------------------------------
Assuming frog.jpg is a picture of a frog, what picture will this code display when run?
A. A frog
B. A picture that’s all gray
C. Nothing: there is a compile error because of an undeclared variable
PLEASE HELP ME! Thanks in advance! (java programming)
Explanation / Answer
Assuming the method is in picture.java, The abobe code will sets the picture that's all gery,
Answer is B, now the expalnation is as
for ( int x=0; x < pic.getWidth(); x++ )
{
for (int y=0; y < pic.getHeight(); y++ )
{
Pixel p = pic.getPixel( x, y );
p.setColor( new Color( 100, 100, 100 ) );
}
}
The two for loops fill the image matrix lets say PIC[][], by getting its height and width as in matrix filling, nothing is done to dispaly the image, the p.setColor( new Color( 100, 100, 100 ) ); will set each pixel of the photo with the grey, hence option A will be discarded and also all the variable are declared , so B is the correct answer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.