Question: Java and plz do the questions from the picture and skip addToAll and use the tester codes thank you! public static void testAddToAll() { System.out.println(

Java and plz do the questions from the picture and skip addToAll and use the tester codes thank you!

Java and plz do the questions from the picture and skip addToAll

public static void testAddToAll() { System.out.println(" Starting atToAll tests"); int[] arr0 = {}; int[] arr1 = {7, 1, 3}; int[] arr2 = {9, 2, 7, 3, 0, 6}; int[] expected0 = {}; int[] expected1 = {8, 2, 4}; int[] expected2 = {11, 5, 7}; int[] expected3 = {14, 7, 12, 8, 5, 11}; A4Exercises.addToAll(arr0, 1); displayResults(Arrays.equals(arr0, expected0), "add 1 to all values in empty array"); A4Exercises.addToAll(arr1, 1); displayResults(Arrays.equals(arr1, expected1), "add 1 to all values in arr1"); A4Exercises.addToAll(arr1, 3); displayResults(Arrays.equals(arr1, expected2), "add 3 to all values in updated arr1"); A4Exercises.addToAll(arr2, 5); displayResults(Arrays.equals(arr2, expected3), "add 5 to all values in arr2"); } public static void testArrayContains() { System.out.println(" Starting arrayContains tests"); int[] arr0 = {}; int[] arr1 = {7, 1, 3}; int[] arr2 = {9, 2, 7, 3, 0, 6}; boolean result = false; result = A4Exercises.arrayContains(arr0, 4); displayResults(!result, "empty array contains 4"); result = A4Exercises.arrayContains(arr1, 1); displayResults(result, "arr1 contains 1"); result = A4Exercises.arrayContains(arr1, 2); displayResults(!result, "arr1 contains 2");

result = A4Exercises.arrayContains(arr2, 9); displayResults(result, "arr2 contains 9"); result = A4Exercises.arrayContains(arr2, 6); displayResults(result, "arr2 contains 6"); result = A4Exercises.arrayContains(arr2, 5); displayResults(!result, "arr2 contains 5"); } public static void testSameInARow() { System.out.println(" Starting sameInARow tests"); int[] arr0 = {}; int[] arr1 = {7, 1, 3}; int[] arr2 = {7, 1, 1, 3}; int[] arr3 = {7, 7, 1, 3}; int[] arr4 = {7, 1, 3, 3}; int[] arr5 = {7, 7, 1, 1, 3, 3}; int[] arr6 = {7, 7, 1, 1, 1, 3, 3}; int[] arr7 = {2, 2, 2, 2, 2, 2, 2}; int result = 0; int expected = 0; result = A4Exercises.sameInARow(arr0); displayResults(result==expected, "same in a row, empty array"); result = A4Exercises.sameInARow(arr1); displayResults(result==expected, "same in a row, {7,1,3}"); result = A4Exercises.sameInARow(arr2); expected = 1; displayResults(result==expected, "same in a row, {7,1,1,3}"); result = A4Exercises.sameInARow(arr3); expected = 1; displayResults(result==expected, "same in a row, {7,7,1,3}"); result = A4Exercises.sameInARow(arr4); expected = 1; displayResults(result==expected, "same in a row, {7,1,3,3}"); result = A4Exercises.sameInARow(arr5); expected = 3; displayResults(result==expected, "same in a row, {7,7,1,1,3,3}"); result = A4Exercises.sameInARow(arr6); expected = 4; displayResults(result==expected, "same in a row, {7,7,1,1,1,3,3}"); result = A4Exercises.sameInARow(arr7); expected = 6; displayResults(result==expected, "same in a row, {2,2,2,2,2,2,2}"); }

public class A4 Exercises { * Purpose: add valToAdd to all elements in the given array * Parameters: int[] array - the array to modify int valToAdd - the value to modify items by * Returns: void - nothing public static void addToAll(int[] array, int valToAdd) { addToAllRecursive (array, valToAdd, array.length-1); } private static void addToAllRecursive (int[] array, int valToAdd, int i) { Purpose: determines whether the given array contains toFind * Parameters: int[] array - the array to search int to Find - the value to search for * Returns: boolean - true if found, false otherwise */ public static boolean arrayContains (int[] array, int toFind) { return arrayContainsRecursive (array, toFind, array.length-1); //To do private static boolean arrayContainsRecursive (int[] array, int toFind, int i) { return false; // so it compiles //To do 1 * Purpose: gets the number of times there are two of the same element in a row * Parameters: int[] array - the array to search * Returns: int - the number of occurrences where two adjacent elements are the same */ public static int sameInARow (int[] array) { return sameInARowRecursive (array, -1, array.length-1); //To do private static int sameInARowRecursive (int[] array, int prev, int i) { return 0; // so it compiles //To do

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!