Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this Java problem. Screenshots of both the problem and the tests are below. /* * ArrayResizer.java * * @author YOUR NAME

I need help with this Java problem. Screenshots of both the problem and the tests are below.

/* * ArrayResizer.java * * @author YOUR NAME  */ public class ArrayResizer { /** Returns true if and only if every value in row r of array2D is non-zero. * Precondition: r is a valid row index in array2D. * Postcondition: array2D is unchanged. */ public static boolean isNonZeroRow(int[][] array2D, int r) { /* to be implemented in part (a) */ return false; // STUB } /** Returns true if and only if every column c of array2D exists for every row and its value is non-zero. * Precondition: c >= 0. * Postcondition: array2D is unchanged. */ public static boolean isNonZeroColumn(int[][] array2D, int c) { /* implementation not shown */ return false; // STUB } /** Returns the number of rows in array2D that contain all non-zero values. * Postcondition: array2D is unchanged. */ public static int numNonZeroRows(int[][] array2D) { /* implementation not shown */ return 0; // STUB } /** Returns a new, possibly smaller, two-dimensional array that contains only rows * from array2D with no zeros, as described in part (b). * Precondition: array2D contains at least one column and at least one row with no zeros. * Postcondition: array2D is unchanged. */ public static int[][] resize(int[][] array2D) { /* to be implemented in part (b) */ return array2D; // STUB } /* There may be other fields, constructors, and methods not shown. */ }

The tests to run are here:

import java.util.*; public class Apcs2021A4 { private static int[][][] tests = { { { 2, 1, 0, }, { 1, 3, 2, }, { 0, 0, 0, }, { 4, 5, 6, }, }, { { 9, 8, 7, 6, }, { 0, 5, 4, 3, }, { 2, 1, 0, -1, }, }, { { 0, }, { 1, 0, }, { 2, 3, 0, }, { 4, 5, 6, 0, }, { 7, 8, 9, 10, }, }, { { 1, }, { 2, 3, }, { 4, 5, 6, }, { 7, 8, 9, 10, }, }, { { 1, 2, 3, 4, 5, }, { 0, 0, 0, 0, }, { 6, 7, 0, }, { 8, }, }, { { 0, -7, -6, -5, }, { -4, 0, -3, }, { 0, -2, 0, }, { -1, }, } }; private static int SIZE = 4; private static int[][][] columnTests = { // These 2D arrays do not meet the precondition for resize. { { 1, 2, 3, 0, }, { 4, 5, 6, 0, }, { 7, 8, 9, 0, }, }, { { 0, 1, }, { 0, 2, 3, }, { 0, 4, 5, 6, }, { 0, 7, 8, }, { 0, 9, }, }, }; public static void main(String[] args) { System.out.println("# Apcs2021A4"); // Test isNonZeroRow. for (int[][] test: tests) for (int i = 0; i = shallowCopy.length || original[i] != shallowCopy[i]) return false; // Check that deep copy contains same values. for (int i = 0; i = deepCopy.length || j >= deepCopy[i].length || original[i][j] != deepCopy[i][j]) return false; return true; } private static int[][] shallowCopy(int[][] original) { if (original == null) return null; final int[][] result = new int[original.length][]; for (int i = 0; i  

Problem Screenshot:

image text in transcribed

Test Screenshot:

image text in transcribed

image text in transcribed

image text in transcribed

ArrayResizer.java 1 /* 2 * ArrayResizer.java 3 4 * @author YOUR NAME 5 */ 6 public class ArrayResizer { 7 /** Returns true if and only if every value in row r of array2D is non-zero. 8 * Precondition: ris a valid row index in array2D. 9 9 * Postcondition: array2D is unchanged. 10 11 public static boolean isNonZeroRowlint (1) array2D, int r) { 12 /* to be implemented in part (a) */ 13 return false; // STUB 14 } 15 16 /** Returns true if and only if every column c of array2D exists for every row and its value is non-zero. 17 * Precondition: C >= 0. 18 * Postcondition: array2D is unchanged. 19 */ * 20 public static boolean isNonZeroColumn(int[][] array2D, int c) { 21 /* implementation not shown */ 22 return false; // STUB 23 } 24 /** Returns the number of rows in array2D that contain all non-zero values. 25 * Postcondition: array2D is unchanged. 26 */ 27 public static int numNonZeroRows(int[][] array2D) { 28 /* implementation not shown */ 29 return; // STUB 30 } 31 32 /** Returns a new, possibly smaller, two-dimensional array that contains only rows 33 * from array2D with no zeros, as described in part (b). 34 * Precondition: array2D contains at least one column and at least one row with no zeros. 35 * Postcondition: array2D is unchanged. 36 37 public static int[][] resize(int[][] array2D) { 38 /* to be implemented in part (b) */ 39 return array2D; // STUB 40 } 41 /* There may be other fields, constructors, and methods not shown. */ } } * 42 8 import java.util.*; 9 10 public class Apcs2021A4 { 11 private static int(01 tests = { 12 { 13 { 2, 1, 0, }, 14 { 1, 3, 2, }, 15 { 0, 0, 0, } 16 { 4, 5, 6, }, 17 }, 18 { 19 { 9, 8, 7, 6, }, 20 { 0, 5, 4, 3, }, 21 { 2, 1, 0, -1, }, 22 } 23 { 24 { 0, }, 25 { 1, 0, }, 26 { 2, 3, 0, }, 27 { 4, 5, 6, 0, }, 28 { 7, 8, 9, 10, 1, 29 }, 30 { 31 { 1, }, 32 { 2, 3, }, 33 { 4, 5, 6, } 34 { 7, 8, 9, 10, }, 35 } 36 37 { 1, 2, 3, 4, 5, }, 38 { 0, 0, 0, 0, } 39 { 6, 7, 0, }, 40 { 8, }, 41 1 42 { 43 { 0, -7, -6, -5, }, 44 { -4, 0, -3, }, 45 { 0, -2, 0, }, 46 { -1, }, 47 } 48 }; 49 private static int SIZE = 4; 50 private static int[][11] column Tests = { 51 // These 2D arrays do not meet the precondition for resize. 52 { 53 { 1, 2, 3, , }) 54 { 4, 5, 6, 0, } 55 { 7, 8, 9, 0, }, 56 } }; G&gn 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 public static void main(String[] args) { System.out.println("# Apcs202144"); // Test isNonZeroRow. for (int[][] test: tests) for (int i = 0; i = shallowCopy. Length || original[i] != shallowCopy[i]) return false; // Check that deep copy contains same values. for (int i = 0; i = deepCopy.length || j >= deepCopy[i].length || original[i][j] != deepCopy[i][j]) return false; return true; } private static int[][] shallowCopy(int[][] original) { if (original == null) return null; final int[][] result = new int[original.length][]; for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions