SHARE
TWEET

Untitled

a guest Feb 20th, 2020 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class TrialGroup {
  5.     String fileName = "";
  6.     private int count, sum, sumOfSquares = 0;
  7.    
  8.     public TrialGroup(String fileName) {
  9.         this.fileName = fileName;
  10.     }
  11.    
  12.     public double getAverage() {
  13.         int tempCount, tempSum = 0;
  14.        
  15.         try {
  16.             BufferedReader inReader;
  17.            
  18.             inReader = new BufferedReader(new FileReader(fileName));
  19.            
  20.             String currentLine = inReader.readLine();
  21.            
  22.             while (currentLine != null) {
  23.                 tempSum = tempSum + Integer.parseInt(currentLine);
  24.                
  25.                 tempCount++;
  26.                
  27.                 currentLine = inReader.readLine();
  28.             }
  29.            
  30.             inReader.close();
  31.         } catch(IOException e) {
  32.             e.printStackTrace();
  33.         }
  34.        
  35.         this.sum = tempSum;
  36.        
  37.         this.count = tempCount;
  38.        
  39.         return (sum / count);
  40.     }
  41.    
  42.     public String getFileName() {
  43.         return this.fileName;
  44.     }
  45.    
  46.     public double getStandardDeviation() {
  47.         int tempSum, sumOfSquares = 0;
  48.        
  49.         try {
  50.             BufferedReader inReader;
  51.             inReader = new BufferedReader(new FileReader(fileName));
  52.             String currentLine = inReader.readLine();
  53.            
  54.             while (currentLine != null) {
  55.                 tempSum = tempSum + Integer.parseInt(currentLine);
  56.                
  57.                 sumOfSquares = sumOfSquares + Integer.parseInt(currentLine);
  58.                
  59.                 count++;
  60.                
  61.                 currentLine = inReader.readLine();
  62.             }
  63.            
  64.             inReader.close();
  65.         } catch (IOException e) {
  66.             e.printStackTrace();
  67.         }
  68.        
  69.         return Math.sqrt((sumOfSquares / count) - ((tempSum / count) * (tempSum / count)));
  70.     }
  71. }
  72.  
  73. public class static void main(String[] args) throws IOException {
  74.     String fileName1, fileName2, fileName3, outFileName;
  75.    
  76.     boolean result1, result2, result3 = false;
  77.    
  78.     Scanner input = new Scanner(System.in);
  79.    
  80.     System.out.println("Please enter the first input file name: ");
  81.    
  82.     fileName1 = input.nextLine();
  83.    
  84.     System.out.println("Please enter the second input file name: ");
  85.    
  86.     fileName2 = input.nextLine();
  87.    
  88.     System.out.println("Please enter the third input file name: ");
  89.    
  90.     fileName3 = input.nextLine();
  91.    
  92.     System.out.println("Please enter the output file name: ");
  93.    
  94.     outFileName = input.nextLine();
  95.    
  96.     input.close();
  97.    
  98.     TrialGroup group1 = new TrialGroup(fileName1);
  99.    
  100.     TrialGroup group2 = new TrialGroup(fileName2);
  101.    
  102.     TrialGroup group3 = new TrialGroup(fileName3);
  103.    
  104.     if (group1.getAverage() - group2.getAverage() > group1.getStandardDeviation()
  105.             && group1.getAverage() - group2.getAverage() > group2.getStandardDeviation()) {
  106.         result1 = true;
  107.     };
  108.    
  109.     if (group1.getAverage() - group3.getAverage() > group1.getStandardDeviation()
  110.             && group1.getAverage() - group3.getAverage() > group3.getStandardDeviation()) {
  111.         result2 = true;
  112.     };
  113.    
  114.     if (group2.getAverage() - group3.getAverage() > group2.getStandardDeviation()
  115.             && group2.getAverage() - group3.getAverage() > group3.getStandardDeviation()) {
  116.         result3 = true;
  117.     };
  118.    
  119.     try {
  120.         BufferedWriter writeOut = new BufferedWriter(new FileWriter(outFileName));
  121.        
  122.         writeOut.write("Statistics:");
  123.        
  124.         writeOut.write(fileName1 + "- Average: " + group1.getAverage() + "\nDeviation: " + group1.getStandardDeviation() + "\n");
  125.        
  126.         writeOut.write(fileName2 + "- Average: " + group2.getAverage() + "\nDeviation: " + group2.getStandardDeviation() + "\n");
  127.        
  128.         writeOut.write(fileName3 + "- Average: " + group3.getAverage() + "\nDeviation: " + group3.getStandardDeviation() + "\n");
  129.        
  130.         writeOut.write("Results:");
  131.        
  132.         writeOut.write(fileName1 + " vs " + fileName2 + ": " + result1);
  133.        
  134.         writeOut.write(fileName1 + " vs " + fileName3 + ": " + result2);
  135.        
  136.         writeOut.write(fileName2 + " vs " + fileName3 + ": " + result3);
  137.     } catch (IOException e) {
  138.         e.printStackTrace();
  139.     }
  140.    
  141.     System.out.println("Output File Generated Successfully!");
  142. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top