subject

This question involves reasoning about arrays of integers. You will write methods in a class named ArrayTester. Write a static method getColumn, which returns a one-dimensional array containing the elements of a single column in a two-dimensional array. The elements in the returned array should be in the same order as they appear in the given column. The notation arr2D [r] [c] represents the array element at row r and column c.
The following code segment initializes an array and calls the getColumn method.
int [] [] arr2D = { {
0,
1,
2
},
{
3,
4,
5
},
{
6,
7,
8
},
{
9,
5,
3
} };
int [] result = ArrayTester. getColumn (arr2D, 1);
When the code segment has completed execution, the variable result will have the following contents.
result: {1, 4, 7, 5}
Write a static method getRow, which returns a one-dimensional array containing the elements of a single row in a two-dimensional array. The elements in the returned array should be in the same order as they appear in the given row. The notation arr2D [r] [c] represents the array element at row r and column c.
int [] result = ArrayTester. getRow (arr2D, 1);
When the code segment has completed execution, the variable result will have the following contents.
result: {3, 4, 5}
Complete these two methods in the program:
hasAllValues
containsDuplicates
Write the static method isLatin, which returns true if a given two-dimensional square array is a Latin square, and otherwise, returns false.
A two-dimensional square array of integers is a Latin square if the following conditions are true.
The first row has no duplicate values. Must use method containsDuplicates in part 3.
All values in the first row of the square appear in each row of the square. Must use hasAllValues in part 3.
All values in the first row of the square appear in each column of the square. Must use hasAllValues in part 3.
This is the given code:
import java. util. Arrays;
public class ArrayTester
{
/** Returns an array containing the elements of column c of arr2D in the same order as they appear in arr2D.
* Precondition: c is a valid column index in arr2D.
* Postcondition: arr2D is unchanged.
*/
public static int [] getColumn(int [][] arr2D, int c)
{
/* your code */
}
/** Returns an array containing the elements of row c of arr2D in the same order as they appear in arr2D.
* Precondition: r is a valid column index in arr2D.
* Postcondition: arr2D is unchanged.
*/
public static int [] getRow(int [][] arr2D, int c)
{
/* your code */
}
/** Returns true if and only if every value in arr1 appears in arr2.
* Precondition: arr1 and arr2 have the same length.
* Postcondition: arr1 and arr2 are unchanged.
*/
public static boolean hasAllValues(int [] arr1, int [] arr2)
{
/* your code */
}
/** Returns true if arr contains any duplicate values;
* false otherwise.
*/
public static boolean containsDuplicates(int[] arr)
{
/* your code */
}
/** Returns true if square is a Latin square ; false otherwise.
* Precondition: square has an equal number of rows and columns.
* square has at least one row.
*/
public static boolean isLatin(int[][] square)
{
/* your code */
}
/ Test /
public static void main(String[] args)
{
int [] [] arr2D = { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {9, 5, 3} };
int [] result = ArrayTester. getColumn (arr2D, 1);
System. out. println(Arrays. toString (result));
int [] result = ArrayTester. getColumn (arr2D, 1);
System. out. println(Arrays. toString (result));
int [] [] square1 = { {1, 2, 3}, {2, 3, 1}, {3, 1, 2} };
int [] [] square2 = { {10, 30, 20, 0}, {0, 20, 30, 10}, {30, 0, 10, 20}, {20, 10, 0, 30} };
int [] [] square3 = { {1, 2, 1}, {2, 1, 1}, {1, 1, 2} };
int [] [] square4 = { {1, 2, 3}, {3, 1, 2}, {7, 8, 9} };
int [] [] square5 = { {1, 2}, {1, 2}};
System. out. println(isLatin (arr2D) + " " + isLatin (square1) + " " + isLatin (square2) + " " +
isLatin (square3) + " " + isLatin (square4) + " " + isLatin (square5));
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 03:00
Jason, samantha, ravi, sheila, and ankit are preparing for an upcoming marathon. each day of the week, they run a certain number of miles and write them into a notebook. at the end of the week, they would like to know the number of miles run each day, the total miles for the week, and average miles run each day. write a program to them analyze their data. your program must contain parallel arrays: an array to store the names of the runners and a two-dimensional array of five rows and seven columns to store the number of miles run by each runner each day. furthermore, your program must contain at least the following functions: a function to read and store the runners’ names and the numbers of miles run each day; a function to find the total miles run by each runner and the average number of miles run each day; and a function to output the results. (you may assume that the input data is stored in a file and each line of data is in the following form: runnername milesday1 milesday2 milesday3 milesday4 milesday5 milesday6 milesday7.)
Answers: 3
question
Computers and Technology, 23.06.2019 04:00
In a word processing program, such as microsoft word, which feature to you choose the desired picture enhancement?
Answers: 2
question
Computers and Technology, 23.06.2019 07:00
You need a quick answer from a coworker. the most effective way to reach your coworker is through a. cloud server b. instant message c. teleconference d. telepresence
Answers: 1
question
Computers and Technology, 23.06.2019 23:00
How do you know if the website is secure if you make a purchase
Answers: 2
You know the right answer?
This question involves reasoning about arrays of integers. You will write methods in a class named A...
Questions
question
Mathematics, 04.12.2020 02:20
question
Mathematics, 04.12.2020 02:20
question
English, 04.12.2020 02:20
Questions on the website: 13722367