Question: I need help writing this method. Complete the flipHorizontalRectangle and flipVerticalRectangle method in the Picture class (4 points) public void flipHorizontalRectangle(int x, int y, int
I need help writing this method.
Complete the flipHorizontalRectangle and flipVerticalRectangle method in the Picture class (4 points)
public void flipHorizontalRectangle(int x, int y, int width, int height)
public void flipVerticalRectangle(int x, int y, int width, int height)
The parameters of these methods are:
(x, y): The top left corner of the rectangle to be flipped (NOTE: in the diagram below, the bottom left corner is highlighted, but (x, y) refer to the TOP left corner).
width, height: The width and height of the rectangle to be flipped.
These methods behave exactly like the two methods from PSA5 with the same name except they must handle rectangles that might be outside of the boundary of the Picture. If part of the specified rectangle falls outside the boundaries of the picture, this method should flip only the portion of the rectangle that is inside the bound of the picture. If the rectangle falls entirely outside the bounds of the picture, this method should do nothing.
Note that the rectangle might go outside the boundary of the Picture in many ways: e.g. x and/or y might be negative, but height and width might be large enough so that the bottom right portion of the rectangle overlaps with the bounds of the picture, or x and y might be in bounds but width and height might make the rectangle go out of bounds. Here is an image that illustrates this more (again, remember that x, y is the top left corner, even though the bottom left corner is highlighted here).:
This is the code I wrote but it didn't work.
public void flipVerticalRectangle(int x, int y, int width, int height) { for (int sourceY = y, i = 1; sourceY >= (y - (height-1)/2); sourceY--, i+=2) { for (int sourceX = x; sourceX = (y - (height-1)); sourceY--) { for (int sourceX = x, i = 1; sourceX Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
