Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write the method int[] sumOfArrays(int [] arr1, int [], arr 2) which has two arr

ID: 3632670 • Letter: W

Question

write the method int[] sumOfArrays(int [] arr1, int [], arr 2) which has two arrays as parameters and returns a new different array. each element of the new array should have the sum of the corresponding elements of the two parameter arrays (its first element should have the sum of the first elements of the two parameter arrays, etc.) for example, if the two parameter arrays had the values of 2,5,6 and 1,3,1 respectively, the returned array should have the values 3,8,7. the parameter should NOT Be modified. if the parameter arrays do not have the same number of elements, the mehtd should throw a java library exception called IllegalArgumentException(it doesnt matter what its argument string is) instead of returnign a value.

Please write j unit testing for this as well.

Explanation / Answer

Hope this helps, please rate! //class named sumArray public class sumArray { //The sumOfArrays method used to sum 2 arrays public int[]sumOfArrays(int[]arr1,int[]arr2){ int[]sum; if(arr1.length!=arr2.length){ throw new IllegalArgumentException("Arrays are not the same size!"); } else{ sum = new int[arr1.length]; for(int i =0;i