Question: Given two classes: public class EncryptionRunner { public static void main ( String [ ] args ) { / / Creates a 2 D array

Given two classes: public class EncryptionRunner {
public static void main(String[] args){
// Creates a 2D array of letters that make up a password
String[][] password ={{"a","l","g"},
{"o","r","i"},
{"t","h","m"}};
// Calls the Encryption object
Encryption encrypt = new Encryption(password);
encrypt.swapLetters();
System.out.println(encrypt.passwordToString());
}
} public class Encryption {
private String[][] letters; // The 2D array of letters that make up the password
/*
* Initializes letters to the 2D array of letters
*/
public Encryption(String[][] letters){
this.letters = letters;
}
/*
* Returns the 2D array of letters
*/
public String[][] getLetters(){
return letters;
}
/*
* Swaps the letter at row 0 column 0 with the letter at
* row 2 column 2 and swaps the letter at row 0 column 2
* with the letter at row 2 colum'n 0
*/
public void swapLetters(){
}
/*
* Returns a String containing each letter in letters
*/
public String passwordToString(){
String result =""; for (int row =0; row < letters.length; row++){
for (int col =0; col < letters[0].length; col++){
result += letters[row][col];
}
}
return result;
}
} In the Encryption class, write the swapLetters() method to perform a diagonal swap of the letters in the 2D array letters. The swapLetters() method should:
Swap the letter at [0,0] with the letter at [2,2]
Swap the letter at [0,2] with the letter at [2,0]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!