Other 2011 FR Questions FR other years Be Prepared Home
A-4
Part (a)
  private void fillBlock(String str)
  {
    int i = 0;

    for (int r = 0; r < numRows; r++)
    {
      for (int c = 0; c < numCols; c++)
      {
        if (i < str.length())
          letterBlock[r][c] = str.substring(i, i+1);
        else
          letterBlock[r][c] = "A";
        i++;
      }
    }
  }


Part (b)
  public String encryptMessage(String message)
  {
    String code = "";
    while (message.length() > 0)
    {
      int n = numRows * numCols;
      if (n > message.length())
        n = message.length(); 1
      fillBlock(message.substring(0, n)); 2

      code += encryptBlock();
      message = message.substring(n);
    }

    return code;
  }
Notes:
  1. Or:
          int n = Math.min(numRows * numCols, message.length());
    although Math.min is not in the AP subset.
  2. Or simply:
          fillBlock(message);
    

Other 2011 FR Questions | Back to Contents

Copyright © 2011 by Skylight Publishing
support@skylit.com