ITEC 120
2D Array 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. Read this code and see what it's doing. You can copy parts of it and make changes to write your tests.

You cannot write pass/fail tests for the print method because the print method is void and does not return a value. The only way to "test" such a method is to visually inspect the output. Be sure to call the print method from your test driver so you can demonstrate that it works. You may also find it useful in your debugging process as you develop your other methods.

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 do not include 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 Lab Submission Folder on D2L.