Forums Register Login

Array Testing Output Confusion

+Pie Number of slices to send: Send
This is for an Intermediate Java class I'm taking this semester. I'm having a problem with testing for out of bounds in an array in my class.

Here is the code that's in the driver program:


And here is the code for the addLine method:


This is the output it produces:
Out of bounds error or start and end points are the same.
Out of bounds error or start and end points are the same.
Out of bounds error or start and end points are the same.
Out of bounds error or start and end points are the same.


Can anyone tell me why it is producing 4 outputs when only three sets of numbers are put through the test? The method tests whether the supplied numbers are not out of bounds of the 2D array, and whether the start and end points do not equal each other. The point of the driver code here is to make sure the driver rejects the numbers.

Also, I'm not sure if my code is correct to draw a straight line in an array of bytes. 0 is a black pixel, 1 is a white pixel. So I have a 2D array of bytes (pixels).

Thanks for any help on this!
+Pie Number of slices to send: Send
I can't tell from the code you've posted; try adding the following line at the start of your method:



This will tell you the parameters that it's working with.
+Pie Number of slices to send: Send
Actually, that helped me figure out why its printing 4 lines. See the driver program goes through all these tests with the class (the driver is provided, we have to write the class) and it was moving onto the next test without me realizing it. I'm always forgetting to add stuff like the line you provided when debugging. Thanks!

Any advice on the code for drawing the line in the array?
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1039 times.
Similar Threads
Converting a two dimensional int array into a byte array
Problem checking condition in a loop
Java Program for File Differences
Changing individual pixels in an image
Conversion Long to byte[]
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:03:54.