• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Testing Output Confusion

 
Greg Roberts
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Roberts
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic