This question is based on the Point class below:
public class Point
{
/** The coordinates. */
private int x;
private int y;
public Point (int xValue, int yValue)
{
x = xValue;
y = yValue;
}
/** @return the x-coordinate of this point */
public int getx()
{ return x; }
/** @return the y-coordinate of this point */
public int gety()
{ return y; }
/** Set x and y to new_x and new_y. */
public void setPoint(int new_x, int new_y)
{
x = new_x;
y = new_y;
}
//Other methods are not shown.
}
The method changeNegs below takes a matrix of Point objects as parameter and replaces every Point that has as least one negative coordinate with the Point (0,0).
/** @param pointMat the matrix of points
* Precondition: pointMat is initialized with Point objects.
* Postcondition: Every point with at least one negative coordinate
* has been changed to have both coordinates
* equal to zero.
*/
public static void changeNegs (Point [][] pointMat)
{
/* code */
}
Which is a correct replacement for /* code */?
I
for (int r = 0; r < pointMat.Length; r++)
for (int c = 0; c < pointMat[r].Length; c++)
if (pointMat[r][c].getx() < 0
|| pointMat[r][c].gety() < 0)
pointMat[r][c].setPoint(0, 0);
II
for (int c = 0; c < pointMat[0].Length; c++)
for (int r = 0; r < pointMat.Length; r++)
if (pointMat[r][c].getx() < 0
|| pointMat[r][c].gety() < 0)
pointMat[r][c].setPoint(0, 0);
III
foreach (Point[] row in pointMat)
foreach (Point p in row)
if (p.getx() < 0 || p.gety() < 0)
p.setPoint(0, 0);
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III