Assessment 4_9_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 two 2D grids of the same dimensions. Return a 2D grid of the same dimensions were the two grids are multipled together. For example, if the user enters [[1, 2], [3, 4, 5], [6]] and [[2, 3], [1, 2, 1], [2]] your code would return the array [[2, 6], [3, 8, 5], [12]].

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_9_Sample{

  public static int[][] multGrid(int[][] arr1, int[][] arr2){
    int [][] ans = new int [2][];
    return ans; 
  }

  public static void main(String[] args){

    int [][] arr1a = {{}};
    int [][] arr1b = {{}};
    int [][] result1 = {{}};
    System.out.println("test1: " + Arrays.deepEquals(multGrid(arr1a, arr1b), result1));
    int [][] arr2a = {{3}};
    int [][] arr2b = {{2}};
    int [][] result2 = {{6}};
    System.out.println("test2: " + Arrays.deepEquals(multGrid(arr2a, arr2b), result2));
    int [][] arr3a = {{3, 1}};
    int [][] arr3b = {{2, 1}};
    int [][] result3 = {{6, 1}};
    System.out.println("test3: " + Arrays.deepEquals(multGrid(arr3a, arr3b), result3));
    int [][] arr4a = {{3, 1}, {2}};
    int [][] arr4b = {{2, 1}, {5}};
    int [][] result4 = {{6, 1}, {10}};
    System.out.println("test4: " + Arrays.deepEquals(multGrid(arr4a, arr4b), result4));
    int [][] arr5a = {{3, 1}, {2}, {}, {1, 2}};
    int [][] arr5b = {{2, 1}, {5}, {}, {3, 4}};
    int [][] result5 = {{6, 1}, {10}, {}, {3, 8}};
    System.out.println("test5: " + Arrays.deepEquals(multGrid(arr5a, arr5b), result5));
  }

}