AveragingNumbersJAVA Can you please help my fix my JAVA code
AveragingNumbers.JAVA
Can you please help my fix my JAVA code, or you can help me create new program follow the requirements.
Thank you.
Lies. D@^# Lies, and Statistics Lies. D@Lies, and Statistics Write a class AveragingNumbers with the following static methods I/ The following method takes the original array, and II uses Arrays.sort to create a new, sorted array II original is not modified in any way public static double[ lo ToHi(double[l original) I/ The following method takes the original array, and I/ returns a new array sorted starting with the highest number II The original array is not modified in any way // Hint: you can call hiToLo to make life easier in this method public static doublef] hiToLo (double[l original) I/ The following method returns the average of the given array public static double avg(doublel original) I The main method II 1: will create a double containing one million (1,000,000) Il/ elements II 2: It will assign a random number between 0 and 1 to each element I 3: It will use the avg method to calculate the average of the array. Call this value averageRandom 4: It will use lo ToHi to create a new sorted array of the same values, II and calculate its average using avg. Call this value averageLo ToHi 5: It ll use hiToLo to create a new array sorted from the highest I/ 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(Sting 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 lo ToHi until you need it for main\'s step 4, and dont 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;
public class HelloWorld
 {
     public static int n=10;
   
     public static double avg(double [] original)
     {
         double sum=0,average=0;
         for(int i=0;i<n;i++)
             sum=sum+original[i];
         average=sum/n;
         return average;
     }
   
     public static double [] loToHi(double [] original)
     {
         int i,j;
         double [] arr= new double[n];
         double temp;
         for(i=0;i<n;i++)
         {
             arr[i]=original[i];
         }
         System.out.println(\"\ Duplicate Array is : \");
         for(i=0;i<n;i++)
         System.out.printf(\"%.1f \",arr[i]);
         for (i = 0; i < n; i++)
         {
             for (j = i + 1; j < n; j++)
             {
                 if (arr[i] > arr[j])
                 {
                     temp = arr[i];
                     arr[i] = arr[j];
                     arr[j] = temp;
                 }
             }
         }
         System.out.print(\"\ Low to High:\");
         for (i = 0; i < n; i++)
             System.out.printf(\"%.1f \",arr[i]);
         return arr;
     }
   
     public static double [] HiToLo(double [] original)
     {
         int i,j;
         double [] arr= new double[n];
         double temp;
         for(i=0;i<n;i++)
         {
             arr[i]=original[i];
         }
         System.out.println(\"\ Duplicate Array is : \");
         for(i=0;i<n;i++)
         System.out.printf(\"%.1f \",arr[i]);
         for (i = 0; i < n; i++)
         {
             for (j = i + 1; j < n; j++)
             {
                 if (arr[i] < arr[j])
                 {
                     temp = arr[i];
                     arr[i] = arr[j];
                     arr[j] = temp;
                 }
             }
         }
         System.out.print(\"\ High to Low:\");
         for (i = 0; i < n; i++)
             System.out.printf(\"%.1f \",arr[i]);
         return arr;
     }
   
      public static void main(String []args)
      {
          double [] original= new double[n];
          double averageRandom=0;
          double averageLoToHi=0;
          double averageHiToLo=0;
          for(int i=0;i<n;i++)
          original[i] = (Math.random() * 2); //assign random numbers between 0 to 1
          System.out.println(\"Original Array is : \");
          for(int i=0;i<n;i++)
          System.out.printf(\"%.1f \",original[i]);
          averageRandom=avg(original);
          double [] lotohi= loToHi(original);
          averageLoToHi=avg(lotohi);
          double [] hitolo= HiToLo(original);
          averageHiToLo=avg(hitolo);
          System.out.printf(\"\ Average of Array with random numbers: \"+averageRandom);
          System.out.printf(\"\ Average of Array sorted Low to High:\"+averageLoToHi);
          System.out.printf(\"\ Average of Array sorted High to Low:\"+averageHiToLo);
          if((averageRandom==averageLoToHi)&&(averageRandom==averageHiToLo))
              System.out.print(\"\ Three averages are identical\ \");
          else
             System.out.print(\"\ Three averages are not identical!!!\  \");
      }
 }
 you can chane the value of n according to the need



