ArrayTester FRQ had you working with 2 methods inside a class called
ArrayTester. There were also 2 methods,
containsDuplicates that were listed as Implementation not Shown. When you see this on a FRQ you almost certainly will be calling those methods somewhere in your solution. Otherwise they wouldn’t have bothered listing them.
getColumn, tasked you with implementing a method that creates an array out of the values in a single column in a matrix. Consider the following matrix
mat the call
getColumn(mat, 2) would return the array
[3, 7, 11, 15, 19] which are the values in column 2. Remember that in Java arrays are 0-indexed.
The second part has you check if a given matrix is a Latin Square. It takes 3 conditions for a matrix to be a Latin Square.
- First row contains no duplicate values
- All rows contain the same set of values
- All columns contain the same set of values
For example, this is a Latin Square.
Note that the first row contains the values 1 through 5 without any duplicates. And each row and column also contains the values 1 through 5.
We’re also told that there are the same number of rows and columns.
First check calls the
containsDuplicates method to make sure that all values in the first row are unique. Then a pair of loops go through each row and then each column to check that every row and column contain the same values as the first row. Notice that we’re calling the
hasAllValues each time and using the
getColumn method we implemented in part A to check the columns.
Want to stay in touch and keep up to date with the latest posts @ CompSci.rocks?