  use javaDevelop a program which allows the user to enter numbers into an array. Input will be as follows: The user will enter the total number of integers to be entered into the array. The user will then enter that number of unique integers (negative or positive). Do not allow the number of values entered to exceed the array size.Develop methods to: ‘main’ method.Print the array Sort the array ( YOU MUST DEVELOP YOUR OWN SORT METHOD – don’t use someone else’s)Determine the highest value Determine the lowest valueCalculate the average value (double)

Question

use java

Develop a program which allows the user to enter numbers into an array. Input will be as follows: The user will enter the total number of integers to be entered into the array. The user will then enter that number of unique integers (negative or positive). Do not allow the number of values entered to exceed the array size.

Develop methods to: ‘main’ method.

Print the array Sort the array ( YOU MUST DEVELOP YOUR OWN SORT METHOD – don’t use someone else’s)

Determine the highest value Determine the lowest value

Calculate the average value (double)

Step 1

Program plan:

• Import the required packages.
• Define a class named “ArraySort”.
• Define a “main()” method.
• Declare the required variables.
• Get the size of an array from the user and store it to the variable.
• Get the array values from the user.
• Call “sort()” method to sort the array.
• Call “getHighest()” method to determine the highest value.
• Call “getLowest()” method to determine the lowest value.
• Call “getAvg()” method to determine the average value.
• Then print statement to print the results.
• Define a “sort()” method.
• “for” loop to sort the array values.
• Define a “getHighest()” method.
• “for” loop to iterate the sorted array values.
• “if” statement to check the highest value and return.
• Define a “getLowest()” method.
• “for” loop to iterate the sorted array values.
• “if” statement to check the lowest value and return.
• Define a “getAvg()” method.
• “for” loop to iterate the sorted array values and compute the total.
• Compute and return average of the array values.
Step 2

Program:

// Import the required packages
import java.util.Scanner;

// Definition of ArraySort class
public class ArraySort {

// Definition of main() method
public static void main(String[] args) {

// Declaration of requird variables
int highestVal, lowestVal;
double avg;

// Creation of object for scanner
Scanner scan = new Scanner(System.in);

// Get the size of an array from the user
System.out.print("Enter the size of an array:");

// Store the size in arrSz
int arrSz = scan.nextInt();

// Array creation
int[] arr = new int[arrSz];

// for loop to iterate and get the integer from the user
for (int count = 0; count < arr.length; count++) {

// Print statement
System.out.print("Enter an integer: ");

// Store the integers to the array
arr[count] = scan.nextInt();
}

// Call sort() method to Sort the array
sort(arr);

// Call getHighest() method to determine the highest value
highestVal = getHighest(arr);

// Call getLowest() method to determine the lowest value
lowestVal = getLowest(arr);

// Call getAvg() method to determine the avg value
avg = getAvg(arr);

// Print statement
System.out.println("The sorted array values are: ");

// for loop to iterate and print the sorted array values
for (int count = 0; count < arr.length; count++) {

// Print the array
System.out.println(arr[count]);
}

// Print the highest value
System.out.println("The highest value in the array is: " + highestVal);

// Print the lowest value
System.out.println("The lowest value in the array is: " + lowestVal);

// Print the average of the array values
System.out.println("The average of the array values is: " + avg);

}

// Defintion of sort() method
public static void sort(int[] arr) {

// Declare an integer variable temp
int temp;

/* for loop to iterate the loop and index 1 is
compared to the array length and incremented */
for (int indx1 = 0; indx1 < arr.length; indx1++) {

/* for loop to iterate the loop and index 2 is
compared to the array length and incremented */
for (int indx2 = indx1 + 1; indx2 < arr.length; indx2++) {

// If the first number is greater than the second,
// the two numbers switch indx positions. We store
// the second number first so it's not overwritten.
//-------------------------------------------------

// Check f...

Want to see the full answer?

See Solution

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Computer Science 