Java 统计方法

Java 统计方法,java,statistics,Java,Statistics,所以在我的代码中,似乎在fillRandomArray方法中,我没有得到100个随机数的数组,而是得到了直接的零,我不知道如何修复它。在我看来,问题与第一个for循环有关,或者可能与公共类统计模型中双数组的声明有关 import javax.swing.*; import java.util.*; import java.util.Arrays; public class statisticalModel { //Initates a place for the normal curv

所以在我的代码中,似乎在fillRandomArray方法中,我没有得到100个随机数的数组,而是得到了直接的零,我不知道如何修复它。在我看来,问题与第一个for循环有关,或者可能与公共类统计模型中双数组的声明有关

import javax.swing.*;
import java.util.*;
import java.util.Arrays;

public class statisticalModel {
    //Initates a place for the normal curve to be placed.
    static double Ho;
    //Real proportion of data statistic.
    static double Ha;
    //Estimated real proportion of data statistic.
    static int Pop;
    //Population size.
    static int Zscore;
    //Z score, or the amount of standard deviations away from the mean.
    //Z score = sqrt(P(1-p)/N)
    static double stdDev;
    //Standard Deviation, follows the 65, 95, 99 model.  65 percent of all scores
    //fall in one standard deviation of the mean.  95 percent of all scores fall
    //within two standard deviations of the mean.  99 percent of all scores fall
    //within three standard deviations of the mean.
    static double mean;
    //The average of all the scores of the array.
    static double variance;
    //The average difference between sets of values within the array.
    static double[] meanScores = new double[100];
    //Array meant to generate a set of random values within the normal curve of
    //the model, following the 65, 95, 99 rule.
    static String desiredValue = "";
    //This is a string set to the user's command.  Tells whether or not the value should
    //be lower than, higher than, or not equal to Ho.
    static Scanner sc = new Scanner(System.in);
    //Scanner to take in values listed above.
    static int size = 100;
    //Variable that measures the size of the array.
    static int temporary;
    //Value Holder for For Loops, While Loops, If Statements, etc.
    static double pValue;

    //P Value which represents how far a statistic deviates from the expected mean of a population.
    public static void main(String args[])
    {
        runStatisticalMethod();
    }

    public static void runStatisticalMethod()
    {
        takeInData();
        calculateStats();
        System.out.println(Arrays.toString(meanScores));
        explainSolution();
    }

    public static void takeInData()
    {
        System.out.println("Please enter your desired Ho");
        Ho = sc.nextDouble();
        System.out.println("Please enter your desired Ha");
        Ha = sc.nextDouble();
        System.out.println("Please enter your desired population size");
        Pop = sc.nextInt();
        System.out.println("Thanks for entering your data.  Your data will be compiled below");
    }

    //Fills the array meanScores with random integers.
    public static void fillRandomArray()
    {
        for (int z = 0; z < 100; z++) {
            meanScores[z] = (Math.random() * 100) + (stdDev * 3);
        }
        assignStdDev();
        for (int x = 0; x < 99; x++) {
            for (int y = 0; y < 99; y++) {
                if (meanScores[y] >= meanScores[y + 1]) {
                    double valueHolder1 = meanScores[y];
                    double valueHolder2 = meanScores[y + 1];
                    meanScores[y + 1] = valueHolder1;
                    meanScores[y] = valueHolder2;
                }
            }
        }
    }

    public static void assignStdDev()
    {
        for (int x = 5; x >= 5 && x <= 95; x++) {
            meanScores[x] -= (stdDev * Math.random());
        }
        for (int x = 31; x >= 31 && x < 66; x++) {
            meanScores[x] -= (stdDev * Math.random());
        }
    }

    //Calculates a set of statistics including standard deviation, z-score, mean,
    //interquartile range, probability, and variance.
    public static void calculateStats()
    {
        //Calculates the Mean of the inputted variables and normal curve.
        int sum = 0;
        for (int a = 0; a < 100; a++) {
            sum += a;
        }
        mean = sum / size;
        //Calculate the Variance of the inputted variables and normal curve.
        for (int b = 0; b < 100; b++) {
            temporary += (b - mean) * (b - mean);
        }
        variance = temporary / size;
        //Calculate the Standard Deviation of the inputted variables and normal curve.
        stdDev = Math.sqrt(variance);
        //Calculate the P-Value and use the p value to determine whether or not the hypothesis is valid.
        pValue = (Ha - Ho) / (stdDev / Math.sqrt(Pop));
    }

    //This method explains the numbers generated in terms of statistics and analyzes
    //if the hypothesis is probably.  If not, a possible solution is proposed with
    //regards to what should be changed.  Also explains the curve of the graph.
    public static void explainSolution()
    {
        if (Math.abs(pValue) < .05) {
            System.out.println(
                "Based on the information you have given me, the hypothesis test seems to show information that your Ha is possibly correct, thus failing to reject your hypothesis");
        } else if (Math.abs(pValue) > .05) {
            System.out.println(
                "Based on the information you have given me, the hypothesis test seems to lack information to show that your Ha is possibly correct, thus rejecting your hypothesis");
        }
    }
}

但是你在哪里调用fillRandomArray??@ΦXocę웃Пepeúpaツ 是的,我已经测试过了,你也不要调用assignStdDev,更新你的runstatisticalmethod来堆栈溢出!看起来您需要学习使用调试器。请随便吃点。如果您以后仍然有问题,请随时回来提供更多详细信息。