Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions