Assessment 4_5_sample
Instructions
This assessment is designed to be completed in 10 minutes or less.
Copy the template below and get all the test cases to pass. Hard-coding answers will not receieve credit; your solution must work for valid arrays.
The problem
Imagine that the user provides a width and height. Generate a two dimensional list such that each element is the sum of the (row plus the column) plus the value in the preceding cell. Both rows and columns should start at zero in the top left cell.
For example, if the user enters the width and height of 2
, your code would return the list [[0,1], [2,4]]
.
Please do not use any Java code or libraries that we have not covered in class; this defeats the purpose of the assessment and will not receive credit.
Code Template and Test cases
import java.util.Arrays;
public class Assess4_5_Sample{
public static int[][] createGrid(int width, int height){
int [][] result = {{}};
return result;
}
public static void main(String[] args){
int [][] arr1 = {{0}};
System.out.println("test1: " + Arrays.deepEquals(createGrid(1,1), arr1));
int [][] arr2 = {{0}, {1}};
System.out.println("test2: " + Arrays.deepEquals(createGrid(1,2), arr2));
int [][] arr3 = {{0, 1}, {2, 4}};
System.out.println("test3: " + Arrays.deepEquals(createGrid(2,2), arr3));
int [][] arr4 = {{0, 1, 3}, {4, 6, 9}, {11, 14, 18}};
System.out.println("test4: " + Arrays.deepEquals(createGrid(3,3), arr4));
}
}