Question: Exercise 1: Finding the maximum value (5 points) int myMaximum(final int[] a, int curUsage); Provide an implementation of the myMaximum method in a class whose

Exercise 1: Finding the maximum value (5 points)

int myMaximum(final int[] a, int curUsage);

Provide an implementation of the myMaximum method in a class whose declaration is shown above. The first argument of the method is an array of int and the second argument is the number of ints that are in the array (the number of slots are actually used). The method returns the largest int that is in the array. The method returns Integer.MIN_VALUE if the array is empty.

If you define this method in the same class containing static main method, you need to define it as a static method. Write test code that thoroughly tests the method.

Exercise 2: Appending ArrayList (5 points)

void appendArrayList(ArrayList v, final ArrayList w);

Provide an implementation of the appendArrayList method in a class whose declaration is shown above. Both arguments of the method are ArrayLists of Integer. The method should modify ArrayList v by appending to it all the elements from w. For example, if v = (4, 2, 5) and w = (11, 3), thenv will become (4, 2, 5, 11, 3) as a result of calling the method.

If you define this method in the same class containing static main method, you need to define it as a static method. Write test code that thoroughly tests the method.

Exercise 3: Counting occurrences (5 points)

int countOccurrences(final int[] v, int k);

Implement the method countOccurrences in a class whose declaration appears above. The first argument of the method is an array v of integers and the second argument is an integer k. The method returns the number of times k occurs in v.

If you define this method in the same class containing static main method, you need to define it as a static method. Write test code that thoroughly tests the method.

Exercise 4: Two-dimensional Arrays (5 points)

boolean isAllZeros(final int[][] a);

Implement the method isAllZeros in a class that uses a loop nested inside another loop to determine whether a 2-dimensional array contains only zeros. A declaration of the method is shown above. The array passed into the method will have 10 rows and 20 columns. The method returns false if the array is empty

If you define this method in the same class containing static main method, you need to define it as a static method. Write test code that thoroughly tests the method.

Exercise 5: Identical Arrays (5 points)

boolean areIdentical(final int[] a, final int[] b);

Write a predicate method that checks whether two arrays are identical (contain exactly the same elements in the same order). A declaration of the method is shown above. The method returns true if the two arrays are identical (or both of them are empty); otherwise it returns false.

If you define this method in the same class containing static main method, you need to define it as a static method. Write test code that thoroughly tests the method.

Exercise 6: Calculating the Average Value (5 points)

double myAverage (final int[] v);

Implement a method that calculates the average value for all numbers in the array passed through its argument. The method returns 0.0 if the array is empty.

If you define this method in the same class containing static main method, you need to define it as a static method. Write test code that thoroughly tests the method.

Exercise 7: Ordered Arrays (5 points)

boolean isStrictlyIncreasing(final int[] v);

Write a predicate method called isStrictlyIncreasing that checks whether an array of integers contains values that are in strictly increasing order. A declaration of the method is shown above. The method returns true if the elements are in strictly increasing order; otherwise it returns false. For example, it will return true for v = (-2, 4, 5, 6, 8) and it will return false for (3, 4, 6, 6, 9).

If you define this method in the same class containing static main method, you need to define it as a static method. Write test code that thoroughly tests the method.

Exercise 8: Reverse an Array (5 points)

void reverseArray(int[] v);

Write a method called reverseArray that reverses array elements so that the first element becomes the last element, the second element becomes the second to last element, and so on, with the old last element now first. Do not just reverse the order in which they are printed; actually change the way they are stored in the array. You cannot create a second array; just rearrange the elements within the array you have. (Hint: Swap elements that need to change places.)

If you define this method in the same class containing static main method, you need to define it as a static method. Write test code that thoroughly tests the method.

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!