Assessment 4_10_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. The first grid will have a single row of length N, while the second grid would have a single column with N elements in it. Return the sum of multiplying each pair of elements in the same slot if you took the transpose of one of the 2D grids.

For example, if the user enters [[1, 2, 3, 5]] and [[2], [3], [4], [5]], your code would return 45 (which is 12 + 23 + 34 + 55).

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

  public static int product(int[][] arr1, int[][] arr2){
    int ans = -9999999;
    return ans; 

  }

  public static void main(String[] args){

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

}