ArrayTester - Part B

Part b. 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. 1) The first row has no duplicate values. 2) All values in the first row of the square appear in each row of the square. 3) All values in the first row of the square appear in each column of the square.

../_images/LatinSquareEx.png

The ArrayTester class provides two helper methods: containsDuplicates and hasAllValues. The method containsDuplicates returns true if the given one-dimensional array arr contains any duplicate values and false otherwise. The method hasAllValues returns true if and only if every value in arr1 appears in arr2. You do not need to write the code for these methods.

../_images/LatinSquareEx2.png

Complete method isLatin below. Assume that getColumn works as specified, regardless of what you wrote in part (a). You must use getColumn, hasAllValues, and containsDuplicates appropriately to receive full credit.

Try and Solve It

Complete the method isLatin below.

You have attempted of activities on this page