/** * * Implement the method below which takes a 2D array of int numbers * as input argument and returns the average of
Posted: Fri Jul 01, 2022 5:41 am
Please do the implementation below the where that wrote "Yourimplementation" and write the same class as the pictures donot change anything thanks and there's information below classabout what you should write thanks and that's the Junit testproject all of the task should be pass thanks and please provideyour screen shot of your code that all of the task are passed withthe my junit test that i provided for you
/** * * Implement the method below which takes a 2D array of int numbers * as input argument and returns the average of its elements. * * You can assume that the input array is not null and contains at * least 1 one element. * * * For example: * * * * if inputarray. * * {{9, 2, 3, 4}, {1, 2, 3, 45}, {1, 222, 333, -4}} then return 51.75 {{1, 4}, {12, 42}} then return 14.75 if inputarray. = if inputarrav. = {{20}, {4, 2, 12}} then return 9.5 * if inputarray. = {{81, 28, 4}, {2, 33, -42}, {1, -22,-4}} then return 9.0 * * * @param inputarray 2D input array of integers * @return the average of its elements. */ public static double average2D(int[] [] inputarray) { /* Your implementation of this method starts here. * Recall that : * 1. No System.out.println statements should appear here. Instead, you need to return the result. * * 2. No Scanner operations should appear here (e.g., input.nextInt()). Instead, refer to the input parameters of this method. * */
@Test public void test_00_average2D() { } int[] [] inputarray = {{9, 2, 3, 4}, {1, 2, 3, 45}, {1, 222, 333, -4}}; double avg = ArrayUtility.average2D (inputarray); double exp = 51.75; String error = String.format( } @Test public void test_01_average2D() { int[] [] inputarray = {{9, 2, 3, 4}, {1, 2, 3, 45}, {1, 222, 333, -4}}; double avg = ArrayUtility.average2D (inputarray); double exp = 51.75; "\n Test average2D failed. Returned ( %.2f ) " + " but correct is (%.2f ). \n", avg, exp); final double THRESHOLD = .01; assertTrue (error, Math.abs(exp - avg) < THRESHOLD); } String error =String.format( "\n Test average2D failed. Returned ( %.2f )"+" but correct is (%.2f ). \n", avg, exp); final double THRESHOLD = .01; assertTrue(error, Math.abs(exp - avg) < THRESHOLD); @Test public void test_02_average2D() { int[] [] inputarray = {{9, 2, 33, 4}, {11, 2, 32, 45}, {1, 222, 333, -4}}; double avg = ArrayUtility.average2D (inputarray); double exp = 57.50; String error = String.format( "\n Test average2D failed. Returned ( %.2f ) " + " but correct is (%.2f ). \n", avg, exp); final double THRESHOLD = .01; assertTrue (error, Math.abs(exp - avg) < THRESHOLD); } @Test public void test_03_average2D() { int[] [] inputarray = {{9, 2, 33, 4}}; double avg = ArrayUtility average2D (inputarray); double exp = 12.00; String error = String.format( "\n Test average2D failed. Returned ( %.2f ) " + " but correct is ( %.2f ). \n", avg, exp); final double THRESHOLD = .01; assertTrue (error, Math.abs(exp - avg) < THRESHOLD); } @Test public void test_04_average2D() { int[] [] inputarray = {{9, 2},{ 33, 4},{0,0,0}}; double avg =ArrayUtility.average2D (inputarray); double exp = 6.86; String error = String.format( "\n Test average2D failed. Returned (%.2f ) " + avg, exp); final double THRESHOLD = .01; assertTrue (error, Math.abs(exp - avg) < THRESHOLD); but correct is (%.2f ). \n",