Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

@Test public void testMinValues() { java.util.Random rng = new java.util.Random(SEED); Adler32 check = new Adler32(); for(int i = 0; i < RUNS; i++) { int

@Test public void testMinValues() { java.util.Random rng = new java.util.Random(SEED); Adler32 check = new Adler32(); for(int i = 0; i < RUNS; i++) { int rows = rng.nextInt(SIZE) + 1; double[][] a = new double[rows][1]; for(int j = 0; j < rows; j++) { int cols = rng.nextInt(30); a[j] = new double[cols]; for(int k = 0; k < cols; k++) { a[j][k] = rng.nextDouble() * 100 - 50; } } double[] b = ap.minValues(a); assertEquals(rows, b.length); for(int j = 0; j < rows; j++) { long x = Double.doubleToRawLongBits(b[j]); check.update((int)x); check.update((int)(x >> 32)); } } assertEquals(1342149396L, check.getValue()); }
 @Test public void testZigZag() { java.util.Random rng = new java.util.Random(SEED); Adler32 check = new Adler32(); for(int i = 0; i < RUNS; i++) { int rows = rng.nextInt(SIZE) + 1; int cols = rng.nextInt(SIZE) + 1; int start = rng.nextInt(1000) - 500; int[][] a = ap.zigzag(rows, cols, start); assertEquals(rows, a.length); for(int j = 0; j < rows; j++) { assertEquals(cols, a[j].length); for(int k = 0; k < cols; k++) { check.update(a[j][k]); } } } assertEquals(704566342L, check.getValue()); }

Java programing

This week, it is time to wrangle two-dimensional arrays. Write the class TwoDeeArrayProblems with the following methods. As always, all these methods must be silent so that they print nothing on the console, but for your own debugging purposes during the development, note that the correct way to print out the contents of the two-dimensional array arr using only one line of code would be

System.out.println(java.util.Arrays.deepToString(arr));

1.double[] minValues(double[][] a) that creates and returns the one-dimensional array b whose length equals the number of rows in a. Each element b[i] should equal the smallest element in the i:th row of the parameter array a, or if that row is empty, equal 0.0. Unlike the previous question, in this problem you may not assume that every row has the same length.

2.int[][] zigzag(int rows, int cols, int start) that creates and returns a two-dimensional array of integers with the given number of rows and cols. This array should contain numbers ascending from start listed in order in the consecutive rows, except that every row whose row index is odd is filled in reverse order. For example, if rows is 3, cols is 5 and start is 14, this method would create and return a two-dimensional array with the elements 14 15 16 17 18 23 22 21 20 19 24 25 26 27 28

TEST

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago