Hello I need help in creating a class with array methods, I got so confused.
import java.util.Scanner;
public class ExecuteArray
{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of the array: ");
int arraySize = sc.nextInt();
int[] arrayElements = new int [arraySize];
System.out.println();
for (int x = 0; x < arraySize; x++){
System.out.print("Enter the element for " + "[" + x + "]: ");
arrayElements [x] = sc.nextInt();
}
System.out.println("\n-----------------------------------------");
System.out.println("The elements of array are: ");
for (int x = 0; x < arraySize; x++){
System.out.print(arrayElements[x] + " ");
}
System.out.println("\n\nThe maximum index of array is: ");
System.out.println("The highest value of the array is: ");
System.out.println("The lowest value of the array is: ");
System.out.println("The sum of all elements in the array is: ");
System.out.println("The the average of all elements in the array is: ");
System.out.println("The count of all elements in the array is: ");
}
}
Here's the output:
Enter the size of the array: 5
Enter the element for [0]: 25
Enter the element for [1]: 6
Enter the element for [2]: 5
Enter the element for [3]: 89
Enter the element for [4]: 26
-----------------------------------------
The elements of array are:
25 6 5 89 26
The maximum index of array is:
The highest value of the array is:
The lowest value of the array is:
The sum of all elements in the array is:
The the average of all elements in the array is:
The count of all elements in the array is:
The output must be like this:
Enter the size of the array: 5
Enter the element for [0]: 25
Enter the element for [1]: 6
Enter the element for [2]: 5
Enter the element for [3]: 89
Enter the element for [4]: 26
-----------------------------------------
The elements of array are:
25 6 5 89 26
The maximum index of array is: 4
The highest value of the array is: 89
The lowest value of the array is: 5
The sum of all elements in the array is: 151
The the average of all elements in the array is: 30.2
The count of all elements in the array is: 5
The lower part must be created in another class and needs to be called in the main method using object instantiation.
These are the instructions:
Create a class in a separate file with the following methods. Name the file as ArrayMethods.
maxIndex() - returns the highest index of the array.
maxElement() - returns the highest element in the array.
minElement() - returns the lowest element in the array.
sumElement() - returns the sum of all elements in the array.
averageElement() - returns the average of all elements in the array.
countElement() - returns the number of all elements in the array.
displayElement() - display all the elements/values in the array.