Need help writing a TestTranspose for my code i have above in java
import java. util. Scanner; public class Transpose static void createPatterned2DArray (int arr []ll) t if (arr null) return for (int i 0; i arr. length; ++i) for (int j J 0; j arr [i] length; ++j) t arr [i] [j] 10 arr. length (i 1) j static void print2DArray (int arr if (arr null) return for (int i 0; i arr. length; ++i) t System out un for (int j 0; j arrlil. length; ++j) t System out print (arr [i] [j]
Expert Answer
Also in the test program, in the getIdentificationString() method, DO NOT FORGET TO PUT YOUR NAME. It shows XXX right now.
Please use the following code – modified Transpose and new TestTranspose class.
Please don’t forget to rate the answer if it helped. Thank you very much.
Transpose.java
public class Transpose {
int array[][];
public Transpose(int row, int col)
{
array = new int[row][col];
}
public void createPatterned2DArray()
{
for(int i= 0; i< array.length; ++i){
for (int j = 0; j < array[i].length; ++j){
array[i][j] = 10 + array.length * (i+1) + j;
}
}
}
public void print2DArray()
{
for(int i = 0; i< array.length; ++i){
System.out.println();
for(int j = 0; j < array[i].length; ++j){
System.out.print(array[i][j] + ” “);
}
}
}
public void print2DArrayTransposed()
{
System.out.println();
for(int j = 0; j< array[0].length; ++j){
System.out.println();
for(int i = 0; i < array.length; ++i){
System.out.print(array[i][j] + ” “);
}
}
}
}
TestTranspose.java
import java.util.Scanner;
public class TestTranspose {
public String getIdentificationString()
{
String program=”Program 2b”, student= “XXX”;
return program+”, “+student;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(“Enter the row and column: “);
int row = sc.nextInt();
int cols = sc.nextInt();
Transpose t = new Transpose(row, cols);
t.createPatterned2DArray();
t.print2DArray();
System.out.println();
t.print2DArrayTransposed();
}
}
output
Enter the row and column: 5 7
15 16 17 18 19 20 21
20 21 22 23 24 25 26
25 26 27 28 29 30 31
30 31 32 33 34 35 36
35 36 37 38 39 40 41
15 20 25 30 35
16 21 26 31 36
17 22 27 32 37
18 23 28 33 38
19 24 29 34 39
20 25 30 35 40
21 26 31 36 41