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

15.11.1. Try and Solve It

Complete the method isLatin below.

Before you keep reading...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

You have attempted 1 of 2 activities on this page