Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will create a class named Array.java which will implement the following methods (click on the method to see more details): public static int sum(int[]

You will create a class named Array.java which will implement the following methods (click on the method to see more details):

public static int sum(int[] arr)

public static int sum(int[] arr, int firstIndex, int lastIndex)

public static double average(int[] arr)

public static double average(int[] arr, int firstIndex, int lastIndex)

public static int maxValue(int[] arr)

public static int maxValue(int[] arr, int firstIndex, int lastIndex)

public static int indexOfFirstMaxValue(int[] arr)

public static int indexOfFirstMaxValue(int[] arr, int firstIndex, int lastIndex)

public static int numberOfBelowAverageElements(int[] arr)

public static int numberOfBelowAverageElements(int[] arr, int firstIndex, int lastIndex)

public static void rotateElements(int[] arr)

public static void rotateElements(int[] arr, int rotationCount)

public static void reverseArray(int[] arr)

For example, given the following array: myArray = {45, 22, 18, 89, 82, 79, 15, 69, 100, 55, 48, 72, 16, 98, 57, 75, 44, 32, 21, 14, 7, 16, 49, 58, 72}

Your methods should return the following values:

Array.sum(myArray) should return 1253 Array.sum(myArray, 12, 18) should return 343 Array.sum(myArray, 25, 18) should return -666 Array.sum(myArray, 12, -1) should return -666 Array.sum(myArray, 12, 25) should return -666 Array.sum(myArray, 13, 12) should return -666 Array.average(myArray) should return 50.12 Array.average(myArray, 12, 18) should return 49.0 Array.average(myArray, -1, 18) should return -666.0 Array.average(myArray, 25, 18) should return -666.0 Array.average(myArray, 12, -1) should return -666.0 Array.average(myArray, 12, 25) should return -666.0 Array.average(myArray, 13, 12) should return -666.0 Array.maxValue(myArray) should return 100 Array.maxValue(myArray, 12, 18) should return 98 Array.maxValue(myArray, -1, 18) should return -666 Array.maxValue(myArray, 25, 18) should return -666 Array.maxValue(myArray, 12, -1) should return -666 Array.maxValue(myArray, 12, 25) should return -666 Array.maxValue(myArray, 13, 12) should return -666 Array.indexOfFirstMaxValue(myArray) should return 8 Array.indexOfFirstMaxValue(myArray, 12, 18) should return 13 Array.indexOfFirstMaxValue(myArray, -1, 18) should return -1 Array.indexOfFirstMaxValue(myArray, 25, 18) should return -1 Array.indexOfFirstMaxValue(myArray, 12, -1) should return -1 Array.indexOfFirstMaxValue(myArray, 12, 25) should return -1 Array.indexOfFirstMaxValue(myArray, 13, 12) should return -1 Array.numberOfBelowAverageElements(myArray) should return 13 Array.numberOfBelowAverageElements(myArray, 12, 18) should return 4 Array.numberOfBelowAverageElements(myArray, -1, 18) should return -666 Array.numberOfBelowAverageElements(myArray, 25, 18) should return -666 Array.numberOfBelowAverageElements(myArray, 12, -1) should return-666 Array.numberOfBelowAverageElements(myArray, 12, 25) should return -666 Array.numberOfBelowAverageElements(myArray, 13, 12) should return -666 Array.rotateElements(myArray) should result in myArray = {72, 45, 22, 18, 89, 82, 79, 15, 69, 100, 55, 48, 72, 16, 98, 57, 75, 44, 32, 21, 14, 7, 16, 49, 58} Array.rotateElements(myArray, 6) should result in myArray = {14, 7, 16, 49, 58, 72, 45, 22, 18, 89, 82, 79, 15, 69, 100, 55, 48, 72, 16, 98, 57, 75, 44, 32, 21} Array.reverse(myArray) should result in myArray = {72, 58, 49, 16, 7, 14, 21, 32, 44, 75, 57, 98, 16, 72, 48, 55, 100, 69, 15, 79, 82, 89, 18, 22, 45}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. If your script has a villain, are his motivations clear?

Answered: 1 week ago