Files
  • Main.java
  • Saves
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.util.Scanner;



class TrialGroup {
    private String fileName, fileInput;
    private int count, averageOfSquare, sum, sumOfSquares, currentLine;
    private double sumOfSquaresAverage, average;

    public TrialGroup(String fileName) throws IOException {
        this.fileName = fileName;
        Scanner fileInput = new Scanner(new File(fileName));
        while (fileInput.hasNext()){
            this.count ++;
            currentLine = fileInput.nextInt();
            this.sum = sum + currentLine;
            this.sumOfSquares = sumOfSquares + (currentLine * currentLine);
        average = getAverage();
        sumOfSquaresAverage = sumOfSquares/count;
        }
    }
    public String getFileName() {
        return fileName;
    }
                               
    public double getAverage() {
        sum = sum;
        count = count;
        average = sum / count;
        return average;
    }
    public double getSquare(double sum){
        double square = Math.pow(sum, 2);
        return square;
    }
    public double getStandardDeviation() {
        average = average;
        sumOfSquares = sumOfSquares;
        count = count;
        double squareOfAverage = (average * average);
        double averageOfSquares = sumOfSquares/count;
        double standardDeviation = Math.sqrt(averageOfSquares - squareOfAverage);
        return standardDeviation;
        
        
    }
}
                               
                              
public class PeppersPillMill {
    

    public static void main(String[] args) throws IOException {
        boolean resultsA, resultsB, resultsC;
        double evaluateMedians;
                
        Scanner userInput = new Scanner(System.in);
        System.out.print("Enter file name for Trial 1: ");
        String Trial1 = userInput.nextLine();
        TrialGroup TrialA = new TrialGroup(Trial1);
        
        System.out.print("Enter file name for Trial 2: ");
        String Trial2 = userInput.nextLine();
        TrialGroup TrialB = new TrialGroup(Trial2);
               
        System.out.print("Enter file name for Trial 3: ");
        String Trial3 = userInput.nextLine();
        TrialGroup TrialC = new TrialGroup(Trial3);
        
                System.out.print("What file would you like this saved in? ");
        String saveFile = userInput.nextLine();
        FileWriter outputFile = new FileWriter(saveFile);
        BufferedWriter toFile = new BufferedWriter(outputFile);
        
        evaluateMedians = subtraction(TrialB.getAverage(), TrialC.getAverage());
        resultsA = sigDifference(TrialA.getAverage(), TrialB.getAverage(), TrialA.getStandardDeviation(), TrialB.getStandardDeviation());
        resultsB = sigDifference(TrialA.getAverage(), TrialC.getAverage(), TrialA.getStandardDeviation(), TrialC.getStandardDeviation());
        resultsC = sigDifference(TrialB.getAverage(), TrialC.getAverage(), TrialB.getStandardDeviation(), TrialC.getStandardDeviation());
        
        toFile.write("Statistics:\n");
        toFile.write(TrialA.getFileName() + ": " + "Average = " + TrialA.getAverage() + " Standard Deviation = " + TrialA.getStandardDeviation() + "\n");
        toFile.write(TrialB.getFileName() + ": " + "Average = " + TrialB.getAverage() + " Standard Deviation = " + TrialB.getStandardDeviation() + "\n");
        toFile.write(TrialC.getFileName() + ": " + "Average = " + TrialC.getAverage() + " Standard Deviation = " + TrialC.getStandardDeviation() + "\n");
        toFile.write("Results:\n");
        toFile.write(TrialA.getFileName() + " vs. " + TrialB.getFileName() + ": " + resultsA + "\n");
        toFile.write(TrialA.getFileName() + " vs. " + TrialC.getFileName() + ": " + resultsB + "\n");
        toFile.write(TrialB.getFileName() + " vs. " + TrialC.getFileName() + ": " + resultsC + "\n");
        toFile.close();
    }
    public static boolean sigDifference (double group1, double group2, double standardDeviationA, double standardDeviationB){
        boolean output = false;
        double compareValue = subtraction(group1, group2);
        if (compareValue > standardDeviationA && compareValue > standardDeviationB)
            output = true;
        return output;
    }  
    public static double subtraction(double a, double b){
        double output;
        if (a > b)
            output = a - b;        
        else 
            output = b - a;        
        return output;
    }   
    public static boolean compareDeviation(double standardDeviationA, double standardDeviationB){
        boolean output = false;
        if (standardDeviationA > standardDeviationB)
            output = true;
        return output;
    }
    
}