Question: Need help modifying my code in Java, a little confused . thanks. Below is my original transpose and testtranspose TRANSPOSE: public class Transpose { int

Need help modifying my code in Java, a little confused . thanks. Below is my original transpose and testtransposeNeed help modifying my code in Java, a little confused . thanks.Below is my original transpose and testtranspose TRANSPOSE: public class Transpose {

TRANSPOSE:

public class Transpose {

int array[][];

public Transpose(int row, int col)

{ array = new int[row][col]; }

// Creates the array public void createPatterned2DArray()

{

for(int i= 0; i

for (int j = 0; j

array[i][j] = 10 + array.length * (i+1) + j;

}

}

}

// Two row array public void print2DArray()

{

for(int i = 0; i

for(int j = 0; j

System.out.print(array[i][j]+ " ");

}

System.out.println();

}

}

// 2 column array public void print2DArrayTransposed()

{

//System.out.println();

for(int j = 0; j

System.out.println();

for(int i = 0; i

System.out.print(array[i][j] + " ");

}

} System.out.println(); System.out.println();

}

}

TEST:

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(" ");

int row = sc.nextInt();

int cols = sc.nextInt(); if((row == 0) || (cols == 0)) { System.out.print(" "); return; } else {

Transpose t = new Transpose(row, cols);

t.createPatterned2DArray();

t.print2DArray();

t.print2DArrayTransposed();

//System.out.println(); }

}

}

Instructions for Transpose 2. java class A common event in programming is to modify an existing program with different or new capabilities. In lab 2b you wrote a Java class Transpose java. The change we are making is to have the Transpose2 object store the array instead of the calling program (TestTranspose2) storing it The program printed output and functionality of the methods previously created will not change. We will, however, not allow the test class to call the method to create an array now. [Are you already thinking of how to restrict the access?l Steps to modify Transpose into Transpos Declare, but do not initialize, a private member variable to store a 2-dimensional int array. Change the access modifier for createPatterned2DArray() to private Add new constructor that will create an 2-dimensional array given row and column values as parameters. Do not rewrite creating the array! Allow the constructor to call createPatterned2DArray() and use the array it returns to initialize the class member array variable Add a new method getRows which returns the number of rows in the 2-dimensional array member variable. Add a new method getcols which returns the number of columns in the 2-dimensional array member variable. Modify getIdentificationstring to print this program. As in previous labs, this method returns a string and is not called from your program but graded by the autograder. Program 3b, StudentFirstName StudentLastName Overload print2DArray() by adding a no-arg method o It is tempting to cut and paste the entire method print2DArray(int 1[ 1 array), but let's not! This would give us two sections of nearly identical code: one that used the instance array and one that used the array passed in Instead, call the one-arg method from the no-arg method. Like this public void print2DArray this print2DArray (name OfInstanceArray) Done! Sweet. And no retesting, re-writing. The this isnt strictly necessary but good programming practice

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!