Question
Help modifying this java program (beginner level) to include a results section? I will post my code below. There are two classes. I need help
Help modifying this java program (beginner level) to include a results section? I will post my code below. There are two classes. I need help getting the output file to look like the bottom part of the screenshot. Right now, I just have the statistics section. Your help is appreciated.
-------------------------------------------------------------------------------
import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner;
public class PeppersPillMill { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter Data file 1 path: "); String dataFile1 = scanner.nextLine(); System.out.print("Enter Data file 2 path: "); String dataFile2 = scanner.nextLine(); System.out.print("Enter Data file 3 path: "); String dataFile3 = scanner.nextLine();
TrialGroup groupOne = new TrialGroup(dataFile1); TrialGroup groupTwo = new TrialGroup(dataFile2); TrialGroup groupThree = new TrialGroup(dataFile3); String outStatement1 = "group 1: average = " + String.format("%.2f", groupOne.getAverage()) + " standard deviation = " + String.format("%.2f", groupOne.getStandardDeviation()); String outStatement2 = "group 2: average = " + String.format("%.2f", groupTwo.getAverage()) + " standard deviation = " + String.format("%.2f", groupTwo.getStandardDeviation()); String outStatement3 = "group 3: average = " + String.format("%.2f", groupThree.getAverage()) + " standard deviation = " + String.format("%.2f", groupThree.getStandardDeviation()); System.out.println(outStatement1); System.out.println(outStatement2); System.out.println(outStatement3);
String outfileName= "datafile4.dat";
try( BufferedWriter bufWriter = new BufferedWriter( new FileWriter(outfileName))) {
bufWriter.write(outStatement1); bufWriter.newLine(); bufWriter.write(outStatement2); bufWriter.newLine(); bufWriter.write(outStatement3); bufWriter.newLine(); } catch(IOException ioEx) { System.err.println("Error: Unable to write to the file"); } } }
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;
public class TrialGroup { private String fileName; private int count; private int sum; private int sumOfSquares; public TrialGroup(String fileName) { this.fileName = fileName; count = 0; sum = 0; sumOfSquares = 0; readFileContents(); } public double getAverage() { return (1.0 * sum / count); } public double getStandardDeviation() { double average = getAverage(); double squareOfAverage = average*average; double averageOfSquares=sumOfSquares/count; return Math.sqrt(averageOfSquares-squareOfAverage); } public String getFileName() { return fileName; } private void readFileContents() { File file = new File(fileName); try { Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { count += 1; int value = Integer.parseInt(scanner.nextLine()); sum += value; sumOfSquares += value * value; } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); }
} }
Your program should output: A file with the trial results Your program should ask for the names of 3 files (input files) that contain memory evaluation data for the three groups in this trial. Your program should then ask for a name for the file that will hold the trial results (the output file). All files will be located in the same directory as your program. Each input data file contains a list of integers - one on each line. The study is double-blind, so your program will not know which data file corresponds to which experimental group For each input file, your program should read in the data from the file. Your program will need to calculate the average and standard deviation for that data set. To determine if there is a significant difference between two groups i of the two groups. If the difference between the averages is larger than the standard deviations of both groups, then this is a significant result. For example, given the following statistics . Additionally, the group sizes may be different. Your program will also need to determine if there is a significant difference between each pair of groups in this trial n the trial, your program must compute the positive difference between the averages group 1: average-69.ee, standard deviation 18.42 group 2: average 47.ee, standard deviation. 19.92 group 3: average 51.58, standard deviation 19.2 There is a significant difference between group 1 and group 2, because 69.00 47.00 is greater than 18.42 and 69.00 - 47.00 is greater than 19.92 However, there is not a significant difference between group 1 and group 3, because 69.00- 51.58 is not greater than 18.42 Your program should write the results to an output file. The results file will have two sections. The first section (Statistics) will list the name of each input file, followed by the average and then the standard deviation for that file. The second section (Results) will list the names of the two files being compared and an indication (true or false) of whether or not the result is significant. Here is a generalized example of the output file format statistics:Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started