Page 1 of 1

/** * * This average0f0dd method received an array of integers, then calculate the * average of the odd elements of this

Posted: Fri Jul 01, 2022 5:41 am
by answerhappygod
This Average0f0dd Method Received An Array Of Integers Then Calculate The Average Of The Odd Elements Of This 1
This Average0f0dd Method Received An Array Of Integers Then Calculate The Average Of The Odd Elements Of This 1 (297.85 KiB) Viewed 45 times
In Java,
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
/** * * This average0f0dd method received an array of integers, then calculate the * average of the odd elements of this array. * * You can assume that the array is not empty and contains at least 1 * one element. * * * For example: * * * * * * * * * if inputarray. = if inputarray. if inputarrav. = { 2, 4, 6, 3} then if inputarray. = { 11, 25, 12, 50} then {3, 6} then return 3.0 { 1, 1, 1} then return 1.0 return 3.0 return 18.0 * * @param inputarray the input array of integers * @return the average of the ODD elements of the input array of integers, the average of type double * */ public static double average0f0dd (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_average0f0dd() { } } final int[] A = { 12, 4, 6 }; double exp = 0.0; double avg = ArrayUtility.average0f0dd(A); @Test public void test_01_average0f0dd() { String error = String.format( "\n Test average0f0dd failed for %s. Returned ( %.2f )"+" but correct is (%.2f ). \n", Arrays.toString(A), avg, exp); } final double THRESHOLD = .01; assertTrue(error, Math.abs(exp - avg) < THRESHOLD); } @Test public void test_02_average0f0dd() { } final int[] A = { 3, 6 }; double exp= 3.0; double avg = ArrayUtility.average0f0dd (A); String error = String.format( "\n Test average0f0dd failed for %s. Returned ( %.2f ) " + "but correct is ( %.2f ). \n", Arrays.toString(A), avg, exp); final double THRESHOLD= .01; assert True(error, Math.abs(exp avg) < THRESHOLD); final int[] A = {12, 4, 6, 3, 3,5,7 }; double exp= 4.5; double avg = ArrayUtility.average0f0dd(A); String error = String.format( "\n Test average0f0dd failed for %s. Returned ( %.2f )"+" but correct is ( %.2f ). \n", Arrays.toString(A), avg, exp); @Test public void test_03_average0f0dd() { final double THRESHOLD = .01; assertTrue(error, Math.abs(exp avg) < THRESHOLD); final int[] A = {12, 4, 6, 4, 4,4,4,4,4,4,4,1 }; double exp = 1.0; double avg = ArrayUtility.average0f0dd(A); String error = String.format( "\n Test average0f0dd failed for %s. Returned ( %.2f )"+" but correct is (%.2f ). \n", Arrays.toString (A), avg, exp); final double THRESHOLD = .01; assert True (error, Math.abs(exp - avg) < THRESHOLD); @Test public void test_04_average0f0dd() { final int[] A = {12, 4, 6, 4, 4,4,4,4,4,4,4 }; double exp = 0.0; Houble avg = ArrayUtility.average0f0dd (A); String error = String.format( "\n Test average0f0dd failed for %s. Returned ( %.2f )"+" but correct is (%.2f ). \n", Arrays.toString(A), avg, exp); final double THRESHOLD = .01; assert True (error, Math.abs(exp - avg) < THRESHOLD);