Question
Could anyone helps with me for these four methods? First, place you name and your lab partner's name at the top of the Array2Lab.java file.
Could anyone helps with me for these four methods?
First, place you name and your lab partner's name at the top of the Array2Lab.java file.
Step 1: Write the contains method and test it using the Test button until the test for contains is green.
You are not to modify the Array2LabTester.java test cases for the contains method.
The comment above each method explains what the method should do. The Precondition is a statement that describes what you can assume will be true about the parameters to the method. The Postcondition statement lists something that, if your code is correct, will be true when the method returns.
Switch roles, the driver should navigate and the navigator should drive.
Step 2: Write the arrayToString method and test it using the Test button.
Demonstrate your method and show your test case to the lab assistant.
Switch roles, the driver should navigate and the navigator should drive.
Step 3: Write the transpose method and test it using JUnit.
Switch roles, the driver should navigate and the navigator should drive.
Step 4: Write the removeRowAndCol method and test it using JUnit.
Page
of 2
ZOOM
/**
* A collection of methods related to multi-dimensional arrays.
*/
public class Array2Lab {
/**
* Return whether k is in list.
* Precondition: the elements of list are not null.
* @param list the array to be searched.
* @param k the number to search for.
* @return true if k is an element of list, and false otherwise.
*/
public static boolean contains(Object[][] list, Object k) {
return false;
}
/**
* Create a String that has the contents of list. Each row of list
should be on a separate line,
* separated by spaces, and surrounded by { and }.
* The first line of of the output should start with an additional {,
each other line of the output
* should start with a space, and the last line of the output should
have an additional {.
* For example: {{1, 2}, {3, 4}} should be formatted in the String as:
* {{1 2}
* {3 4}}
* @param list the array to print.
* @return the elements of the array, separated by spaces, and
surrounded by { and }, with each row on a separate line.
*/
public static String arrayToString(int[][] list) {
return null;
}
/**
* Create a new array that "flips" a rectangular region of matrix about
the diagonal. So, each row of the output should be a column of the
input.
* Precondition: The region of
matrix[rowStart...rowEnd][colStart...colEnd] exists.
* @param matrix the input two dimensional array.
* @param rowStart the index of the first row of the rectangular
region to flip.
* @param rowEnd the index of the last row of the rectangular region
to flip.
* @param colStart the index of the first column of the rectangular
region to flip.
* @param colEnd the index of the last column of the rectangular
region to flip.
*/
public static int[][] transpose(int[][] matrix, int rowStart, int
rowEnd, int colStart, int colEnd) {
return null;
}
/**
* Creates a new array that is a copy of the input matrix, except that
one row and one column have been removed.
* Precondition: the row index is between 0 (inclusive) and the number
of rows of matrix (not inclusive)
* @param matrix the input two dimensional array
* @param row the index of the row to remove
* @param col the index of the column to remove
*/
public static int[][] removeRowAndCol(int[][] matrix, int row, int col)
{
return null;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started