ITEC 120
L12b: 2D Arrays of ints

Objectives

After successfully completing this lab you will be able to create, print, traverse, and work with 2D arrays of primitive data types.

Assignment

For this assignment you will develop several familiar methods that operate on two-dimensional arrays and you will write a test driver to test your methods.

Create a class called MatrixSrv. In this class, you'll write these methods:

Download MatrixTestDrv.java. This file contains a nice set of tests for sum, min, and sumRows. You will create the tests for max, range, and isFound. (You don't need to test print. The print method is just for your own convenience, so you can print a 2D array to see what your code is doing.) Read this code and see what it's doing. You can copy parts of it and make changes to write your tests.

These test cases test a variety of 2D arrays, including one with just one element, ones with positive and negative values, and jagged arrays (not all rows are the same length). You may use these same arrays for the tests you write if you like, or you may make up new ones, but be sure to include a jagged array, an array with one element, one with all negative numbers, one with all positive numbers, and one with a mix of positive and negative.

These test cases are ignoring the case of an empty array, which is a case we often test. We are not testing for that in this lab because figuring out what sum, for example, should return if it gets passed an empty array is a hard question. Should sum return zero if it is passed an empty array? No, because zero might actually be the sum of the elements in the array passed to sum. If sum is passed an empty array, it should probably throw an exception, which we will be talking about the last week of class.

 

Submit Your Assignment

Submit your MatrixSrv.java and MatrixTest.java to the L12b dropbox on D2L.