Question: Please use explanations in the code. Thank you Picture Flip Add a method called flipVertical to Picture.java. This method will take in 3 parameters, the

Please use explanations in the code. Thank you

Picture Flip

Add a method called flipVertical to Picture.java.

This method will take in 3 parameters, the x and y coordinates of the middle of the box to flip, and the size (length/width) of the square box to flip. For simplicity, assume the size will always be odd. Note that flipVertical should flip the pixels in the box about a vertical axis.

First, this method should figure out the x and y coordinates for the top left point of the box to flip and save those to variables. Then it should figure out the x and y coordinates of the bottom right corner and save those to other variables.

Then you must have two nested for loops. These will loop through the proper (x,y) coordinates, allowing you to flip the specified box.

The outer for loop should loop through all y coordinates, so from the top left y coordinate to the bottom right y coordinate.

The inner for loop should loop through half of the x coordinates, so from the top left x coordinate to the x coordinate that was passed in as a parameter (i.e. the middle x).

Inside of the nested for loops you should get the target pixel, which is the pixel that the for loops are on, and the source pixel, which is the x- opposite of this pixel. Then you should swap their colors. NOTE: Don't forget to use a "friend" variable that will hold one of the colors

when swapping (don't try to use a Pixel object as a friend, it may not work for reasons we haven't yet covered in class). For example, to create a friend variable when swapping two Pixel objects p and q, do:

Color friend = p.getColor();

Method 2: flipHorizontal

Add another method to Picture.java called flipHorizontal. Note that flipHorizontal should flip the pixels in the box about a horizontal axis.

This method is almost exactly like flipVertical except everything is reversed. The outer loop will loop through all of the x pixels, from the top left x to the

bottom right x. The inner loop will loop through half of the y pixels, from the top

left y to the y that was passed in as the parameter (i.e. the middle y).

The inside of the nested loops are pretty much the same, except backwards. I expect you to mess around with it and think about it to figure it out.

Download the PSA4B.java file and save it in your PSA4/bookClasses directory. This file has a lot of code filled in already with several comments labeled TODO to indicate what parts you should change.

Modify the code in the PSA4B.java to add a loop that will iterate 3 times. You may use a for loop or a while loop, but a for loop is more natural to use in this situation, since it is counter-controlled repetition. Each iteration of the loop should include what was given to you, plus the call to your flipHorizontal method.

Also complete the missing lines that are needed to get the input from the user. You MUST use the Scanner class to do this. You will need to write an import statement (before the line that starts public class), create a Scanner object that can read from the keyboard (System.in) in the initializing variables section, and complete the three lines to actually get the user input (x = , y = , size = ).

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!