Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java flip methods I need help debugging. The assignment: This method should copy the whole parameter Picture into the calling object, starting at position (startX,

java flip methods

I need help debugging.

The assignment:

This method should copy the whole parameter Picture into the calling object, starting at position (startX, startY) in the calling object. See the diagram below. Note that the black line in the flipped pictures just shows where the boundary of the copied in part is or would be, and is not actually part of the image.

image text in transcribed

Important notes and hints:

You should not assume that the calling object will be large enough to hold the image passed in in the location specified. If the image to be copied will go out of bounds, simply copy in the part that will fit in the specified position, and ignore the rest.

You may assume that startX and startY will be within the bounds of the calling object.

Your methods should not modify the parameter image. I.e. the image you pass in should be unchanged after the method is called. However, it is acceptable to create a new Picture within the method and modify that newly created Picture object as an intermediate step. You do not have to do this, though.

My code:

https://gist.github.com/Camicam311/36978fc2e625c27c6755e7b7c6e147b1

public void flipHorizontalInto(Picture source, int startX, int startY) { Color tempColor = null; Pixel sourcePixel = null; Pixel targetPixel = null;

for (int sx = startX, tx = startX + source.getWidth() - 1; sx startX + source.getWidth() - 1; sx++, tx--) { for (int sy = startY; sy

public void flipVerticalInto(Picture source, int startX, int startY) { Color tempColor = null; Pixel sourcePixel = null; Pixel targetPixel = null;

for (int sx = startX; sx startY + this.getHeight() - 1; sy++, ty--) { sourcePixel = source.getPixel(sx, sy); tempColor = sourcePixel.getColor(); targetPixel = source.getPixel(sx, ty); sourcePixel.setColor(targetPixel.getColor()); targetPixel.setColor(tempColor); } } }

The testers fail saying the source image was not copied correctly.

canvas source canvas.flipVe rticalInto (source, 2, 5); canvas.flipH 5)canvas.flipHorizontalInto (source, 5, 5); canvas canvas

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

ISBN: 3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

Factors Affecting Conflict

Answered: 1 week ago

Question

Describe the factors that lead to productive conflict

Answered: 1 week ago

Question

Understanding Conflict Conflict Triggers

Answered: 1 week ago