Other 2012 FR Questions FR other years Be Prepared Home
A-4
Part (a)
  public int countWhitePixels()
  {
    int count = 0;
    for (int r = 0; r < pixelValues.length; r++)
      for (int c = 0; c < pixelValues[0].length; c++)
        if (pixelValues[r][c] == WHITE) 1
          count++;

    return count;
  }
Notes:
  1. It would be acceptable to write 255 for WHITE (and 0 for BLACK in Part (b)).


Part (b)
  public void processImage()
  {
    for (int r = 0; r < pixelValues.length - 2; r++)
      for (int c = 0; c < pixelValues[0].length - 2; c++)
        pixelValues[r][c] = Math.max(BLACK, pixelValues[r][c] - pixelValues[r+2][c+2]);
  } 1
Notes:
  1. Math.max is not in the AP subset, but it is OK to use it.  Alternative solution:
      public void processImage()
      {
        for (int r = 0; r < pixelValues.length - 2; r++)
        {
          for (int c = 0; c < pixelValues[0].length - 2; c++)
          {
            int p = pixelValues[r][c] - pixelValues[r+2][c+2];
            if (p < BLACK)
              p = BLACK;
            pixelValues[r][c] = p;
          }
        }
      }

Other 2012 FR Questions | Back to Contents

Copyright © 2012 by Skylight Publishing
support@skylit.com