-5

I need to implement four static methods in a class named ArrayStatistics. Each of the four methods will calculate the mean, median, mode, and population standard deviation, respectively, of the values in the array.

This is my first time working with Java, and cannot figure out what should I do next. I was given some test values for, you guessed it, test out my program.

public class ArrayStatistics {

     public static void main(String[] args) {
         final int[] arr;
         int[] testValues = new int[] { 10, 20, 30, 40 };
         meanValue = a;
         meadianValue = b;
         modeValue = c;
         sqrtDevValue = d;
         average = (sum / count);

         System.out.println("Average is " );
    }

    static double[] mean(int[] data) {
        for(int x = 1; x <=counter; x++) {
            input = NumScanner.nextInt();
            sum = sum + inputNum;
            System.out.println();
        }
        return a;
    }

    static double[] median(int[] data) {
        // ...    
    }

    public double getMedian(double[] numberList) {
        int factor = numberList.length - 1;
        double[] first = new double[(double) factor / 2];
        double[] last = new double[first.length];
        double[] middleNumbers = new double[1];

        for (int i = 0; i < first.length; i++) {
            first[i] = numbersList[i];
        }
        for (int i = numberList.length; i > last.length; i--) {
            last[i] = numbersList[i];
        }
        for (int i = 0; i <= numberList.length; i++) {
            if (numberList[i] != first[i] || numberList[i] != last[i]) middleNumbers[i] = numberList[i];
        }
        if (numberList.length % 2 == 0) {
            double total = middleNumbers[0] + middleNumbers[1];
            return total / 2;
        } else {
            return b;
        }
    }

    static double[] mode(int[] data) {
        public double getMode(double[] numberList) {
        HashMap<Double,Double> freqs = new HashMap<Double,Double>();

        for (double d: numberList) {
            Double freq = freqs.get(d);
            freqs.put(d, (freq == null ? 1 : freq + 1));   
        }
        double mode = 0;
        double maxFreq = 0;    

        for (Map.Entry<Double,Doubler> entry : freqs.entrySet()) {     
            double freq = entry.getValue();
            if (freq > maxFreq) {
                maxFreq = freq;
                mode = entry.getKey();
            }
        }        
        return c;
    }

    static double[] sqrt(int[] sqrtDev) {
        return d;
    }
}
emlai
  • 37,861
  • 9
  • 87
  • 140

1 Answers1

0

This is pretty easy.

public double mean(ArrayList list) {
 double ans=0;
 for(int i=0; i<list.size(); i++) {
 ans+=list.get(i);   }
 return ans/list.size()
 }

` Median:

public void median(ArrayList list) {
     if(list.size()%==2) return (list.get(list.size()/2)+list.get(list.size()+1))/2;
 else return list.get((list.size()/2)+1)
    }

For Mode, just a keep a tally on the frequency of each number occurrence, extremely easy.

For standard deviation find the mean and just use the formula given here: https://www.mathsisfun.com/data/standard-deviation-formulas.html

deepmindz
  • 568
  • 1
  • 5
  • 13