Write a class AveragingNumbers with the following static met
Write a class AveragingNumbers with the following static methods // The following method takes the original array, and // uses Arrays.sort to create a new, sorted array. // original is not modified in any way. public static double[] loToHi(double[] original) // The following method takes the original array, and // returns a new array sorted starting with the highest number. // The original array is not modified in any way. // Hint: you can call hiToLo to make life easier in this method. public static double[] hiToLo(double[] original) // The following method returns the average of the given array public static double avg(double[] original) // The main method // 1: will create a double[] containing one million (1,000,000) // elements. // 2: It will assign a random number between 0 and 1 to each element. // 3: It will use the avg method to calculate the average of the array. Call this value averageRandom. // 4: It will use loToHi to create a new sorted array of the same values, // and calculate its average using avg. Call this value averageLoToHi. // 5: It will use hiToLo to create a new array sorted from the highest // value to the smallest, and calculate its average using avg. Call this value averageHiToLo. // 6: It will print the three averages, one per line. // 7: It will print whether the 3 averages are identical or not. public static void main(String[] args) Hint: Start with main, and write the program for a small array, say 5 elements. First create and populate the array and print each element. Then write and test each of main\'s steps in order, making sure each step works correctly before moving on to the next one. For example, after you can create and populate the array, write step 3 of the main method. This will require writing the avg method. Don\'t worry about a method until you need to use it in the main method. Don\'t write loToHi until you need it for main\'s step 4, and don\'t write hiToLo until you need it for main\'s step 5. Finally, change the array size to a million. Be aware that it may take a few seconds to run (if you\'re holding your breath).
Solution
import java.util.Random;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 public class TestAveragingNumbers
 {
    public static void main(String ss[])
    {
        //Creates 3 arrays for Original, Low to high, and high to low
        Double Or[] = new Double[1000000];
        Double lohi[] = new Double[1000000];
        Double hilo[] = new Double[1000000];
int c;
       //Creates 3 variables to store average
        double averageRandom, averageLoToHi, averageHiToLo;
       
        //Generates random number between 0 and 1
        for(c = 0; c < 1000000; c++)
            Or[c] = new Random().nextDouble();
       //Generates duplicate copy of the original arrays
        Double back[] = Arrays.copyOf(Or,Or.length);
       System.out.println(\"\  Original: \");
        for(c = 0; c < 1000000; c++)
            System.out.print(\" \"+ back[c]);  
       //Calculates the average and displays it for original array
        averageRandom = AveragingNumbers.avg(back);
        System.out.println(\"\  Average of Original Array = \" + averageRandom);
       //Ascending order arrangement
        lohi = AveragingNumbers.loToHi(back);
        System.out.println(\"\  After Sorting loToHi: \");
        for(c = 0; c < 1000000; c++)
            System.out.print(\" \"+ back[c]);  
       //Calculates the average and displays it for low to high array
        averageLoToHi = AveragingNumbers.avg(lohi);
        System.out.println(\"\  Average of LoToHigh Array = \" + averageLoToHi);
       //Descending order arrangement
        hilo = AveragingNumbers.hiToLo(back);
        System.out.println(\"\  After Sorting hiToLo: \");
        for(c = 0; c < 1000000; c++)
            System.out.print(\" \"+ back[c]);  
       
        //Calculates the average and displays it for high to low array
        averageHiToLo = AveragingNumbers.avg(hilo);  
        System.out.println(\"\  Average of HiToLow Array = \" + averageHiToLo);
       //Compares the equality of all 3 averages
        if(averageRandom == averageLoToHi && averageRandom == averageHiToLo && averageHiToLo == averageLoToHi)
            System.out.println(\"\  All 3 averages are Identical \");      
    }
 }
 class AveragingNumbers
 {
    //Arrangement of low to high
    public static Double [] loToHi(Double[] original)
    {
        Arrays.sort(original);
        return original;
    }
   //Arrangement of high to low
    public static Double[] hiToLo(Double[] original)
    {
        Comparator<Double> comp = Collections.reverseOrder();
        Arrays.sort(original, comp);
        return original;
    }
   
    //Calculates average
    public static Double avg(Double[] original)
    {
        Double av, tot = 0.0;
        for(int c = 0; c < 1000000; c++)
            tot = tot + original[c];
        av = tot/5;
        return av;
    }
 }
Output:
For array size 5
Original:
 0.202973829618866 0.9100710104842669 0.9884115012057852 0.7930352701111107 0.6415169457475325
 Average of Original Array = 0.7072017114335123
After Sorting loToHi:
 0.202973829618866 0.6415169457475325 0.7930352701111107 0.9100710104842669 0.9884115012057852
 Average of LoToHigh Array = 0.7072017114335123
After Sorting hiToLo:
 0.9884115012057852 0.9100710104842669 0.7930352701111107 0.6415169457475325 0.202973829618866
 Average of HiToLow Array = 0.7072017114335123
All 3 averages are Identical



