Activity 4.53.1.
Explain in plain English what your code will have to do to answer this question. Use the variable names given above.
https://apstudents.collegeboard.org/courses/ap-computer-science-a/free-response-questions-by-yearRouteCipher that encrypts (puts into a coded form) a message by changing the order of the characters in the message. The route cipher fills a two-dimensional array with single-character substrings of the original message in row-major order, encrypting the message by retrieving the single-character substrings in column-major order.
RouteCipher class is shown below.public class RouteCipher
{
/**
* A two-dimensional array of single-character strings, instantiated in the
* constructor
*/
private String[][] letterBlock;
/** The number of rows of letterBlock, set by the constructor */
private int numRows;
/** The number of columns of letterBlock, set by the constructor */
private int numCols;
/**
* Places a string into letterBlock in row-major order.
*
* @param str the string to be processed Postcondition: if str.length() <
* numRows * numCols, "A" in each unfilled cell if str.length() > numRows *
* numCols, trailing characters are ignored
*/
public void fillBlock(String str)
{
/* to be implemented in part (a) */
}
/**
* Extracts encrypted string from letterBlock in column-major order.
* Precondition: letterBlock has been filled
*
* @return the encrypted string from letterBlock
*/
private String encryptBlock()
{
/* implementation not shown */
}
/**
* Encrypts a message.
*
* @param message the string to be encrypted
* @return the encrypted message; if message is the empty string, returns the
* empty string
*/
public String encryptMessage(String message)
{
/* to be implemented in part (b) */
}
// There may be instance variables, constructors, and methods that are not
// shown
}
fillBlock that fills the two-dimensional array letterBlock with one-character strings from the string passed as parameter str.str is smaller than the number of elements of the array, the string “A” is placed in each of the unfilled cells. If the length of str is larger than the number of elements in the array, the trailing characters are ignored.letterBlock has 3 rows and 5 columns and str is the string “Meet at noon”, the resulting contents of letterBlock would be as shown in the following table.
letterBlock has 3 rows and 5 columns and str is the string “Meet at midnight”, the resulting contents of letterBlock would be as shown in the following table.
k of the string str.str.substring(k, k + 1)
letterBlock array. What type of loop will you use?letterBlock array has two dimensions. How many loops will you use?String method can you use to access partial or full strings within another string?k of the string str?k? (this is hard to visualize, try drawing out some examples)fillBlock below.