ArrayTester

The ArrayTester FRQ had you working with 2 methods inside a class called ArrayTester. There were also 2 methods, hasAllValues and 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.

Part A

Part A, 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.

\(\begin{bmatrix}
1 & 2 & 3 & 4\\
5 & 6 & 7 & 8\\
9 & 10 & 11 & 12\\
13 & 14 & 15 & 16\\
17 & 18 & 19 & 20
\end{bmatrix}\)

Using 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.

Part B

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.

\(\begin{bmatrix}
1&2&3&4&5\\
5&4&2&3&1\\
2&3&5&1&4\\
3&1&4&5&2\\
4&5&1&2&3
\end{bmatrix}\)

Note that the first row contains the values 1 through 5 without any duplicates. And each row and column also contain 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.

Why ClassCube?

Are you spending too much time grading your students' source code?

ClassCube is an online tool for Computer Science teachers that allows you to create lab assignments for your students. They'll submit their code online and ClassCube will automatically grade it for you.

Teaching with ClassCube…

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>