Question: What does this code do? Explain in plain English. The following is a method in the Picture class: 1: public Picture sillyStuff(Picture p, Picture q)

What does this code do? Explain in plain English.

The following is a method in the Picture class:

1: public Picture sillyStuff(Picture p, Picture q)

2: {

3: int w = Math.min(Math.min(p.getWidth(), q.getWidth()), this.getWidth());

4: int h = Math.min(Math.min(p.getHeight(), q.getHeight()), this.getHeight());

// why the two calls to Math.min?

5: Picture x = new Picture(w,h);

6:

7: for (int a = 0; a < x.getWidth(); a++)

8: {

9: for (int b = 0; b

10: {

11: x.getPixel(a,b).setRed(p.getPixel(a,b).getRed());

12: x.getPixel(a,b).setGreen(q.getPixel(a,b).getGreen());

13: x.getPixel(a,b).setBlue(this.getPixel(a,b).getBlue());

14: }

15: }

16: return x;

17: }

1. In the code above, what does line 3 do?

2. In the code above, what does line 5 do?

3. Does the code above make changes to the Picture based on

A) The pixel locations

B) The pixel color values

C) Both pixel location and pixel color value

D) Ordering of parameter values

4. Suppose I want to change the above code to make a picture that is as LARGE is the largest picture. What problems will I

have with my loop as written? Explain your concerns in English.

5. Suppose I have some wacky Picture method that creates a new Picture from the calling object Picture in a kind of wacky

way. Complete the code with an appropriate if statement to make sure that I have no index out of bounds errors.

Please help me #1 - #5 questions!

Thanks in advance! :-)

#java programming

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!