This project requires the use of the following Java program files:
|
Download them to your PC before doing this project. (To download: right click on a link and select "Save Link As")
Abide to the Emory Honor code when doing assignments.
This assignment involves manipulating a two-dimensional array of integers. You will write two static methods of the ArrayResizer class, which is shown below:
public class ArrayResizer { public static boolean isNonZeroRow( int[][] array2D, int r ) { // Write this method for part A (50 pts) return false; // Statement added to prevent compile error // Remove it when you write this method } public static int[][] resize( int[][] array2D ) { // Write this method for part B (50 pts) return null; // Statement added to prevent compile error // Remove it when you write this method } public static int numNonZeroRows( int[][] array2D ) { int numNonZeroRows = 0; for ( int i = 0; i < array2D.length; i++ ) if( isNonZeroRow( array2D, i ) ) numNonZeroRows++; return numNonZeroRows; } } |
Warning:
|
Write the method isNonZeroRow(int[][] array2D, int r) , which returns true if and only if all elements in row r of a two-dimensional array array2D are not equal to zero.
Use the provided Java program file
ArrayResizer.java
to write the
isNonZeroRow method.
Use the provided Java program file
TestA.java
to test the
isNonZeroRow method.
For example, consider the following statement, which initializes a two-dimensional array.
int[][] arr = {{2, 1, 0}, {1, 3, 2}, {0, 0, 0}, {4, 5, 6}}; |
Sample calls to isNonZeroRow are shown below:
Call Return value Reason =========================================================================== ArrayResizer.isNonZeroRow(arr, 0) false At least one value in row 0 is zero. ArrayResizer.isNonZeroRow(arr, 1) true All values in row 1 are non-zero. ArrayResizer.isNonZeroRow(arr, 2) false At least one value in row 2 is zero. ArrayResizer.isNonZeroRow(arr, 3) true All values in row 3 are non-zero. |
Write the method resize(int[][] array2D), which returns a new two-dimensional array containing only rows from array2D with all non-zero values.
The elements in the new array should appear in the same order as the order in which they appeared in the original array.
Use the provided Java program file
ArrayResizer.java
to write the
resize method.
Use the provided Java program file
TestB.java
to test the
resize method.
Example:
int[][] arr = {{2, 1, 0}, {1, 3, 2}, {0, 0, 0}, {4, 5, 6}}; int[][] out = ArrayResizer.resize(arr); |
When the code segment completes, the following will be the contents of out:
{{1, 3, 2}, {4, 5, 6}} |
A helper method, numNonZeroRows(), has been provided for you. The method returns the number of rows in its two-dimensional array parameter that contain no zero values.
You must be on Emory campus (e.g.: Emory unplugged) in order to turn in an assignment
Use your web browser and visit the cs171 turnin website: click here
|
You can turn in your program file
more than once as long as
you turn in before the deadline for the project.
The turn in system will
overwrite the
previous turn in file with
the new file that
you turn in/
Use your web browser and visit the cs171 turnin website: click here
|
If you do not see your NetID and/or a new due-date, send your professor an email - include the wrong message that you are seeing....
You can only make one extension request per assignment.
You have 3 "free" extension requests total.
Additional extension requests only available for qualified circumstances with documentation (such as doctor's note for illness).